我想讓applyAndTruncate
對外界隱藏(也就是從Scoring
模塊以外的任何東西),因爲我真的只用它作爲bestKPercent
和worstKPercent
的骨幹。可以隱藏它嗎?如果沒有,那麼完成我想要做什麼的F#方法是什麼?是否可以在F#模塊中使用私有函數(讓定義)?
module Scoring
let applyAndTruncate f percentage (scoredPopulation:ScoredPopulation) : ScoredPopulation =
if (percentage < 0.0 || percentage > 1.0) then
failwith "percentage must be a number between 0.0 and 1.0"
let k = (int)(percentage * (double)(Array.length scoredPopulation))
scoredPopulation
|> f
|> Seq.truncate k
|> Seq.toArray
let bestKPercent = applyAndTruncate sortByScoreDesc
let worstKPercent = applyAndTruncate sortByScoreAsc
我幾乎不知道F#什麼,但也許[在F#spec](http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html#_Toc270597594)很有幫助。您似乎可以添加輔助功能註釋來讓綁定。 – 2011-09-11 15:45:08