【发布时间】:2011-09-11 15:38:14
【问题描述】:
我想让applyAndTruncate 对外界隐藏(即对Scoring 模块之外的任何东西),因为我实际上只将它用作bestKPercent 和worstKPercent 的主干。是否可以隐藏它?如果没有,完成我想做的事情的 F#ish 方式是什么?
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# 几乎一无所知,但也许 the F# spec 会有所帮助。看来您可以添加可访问性注释来让绑定。