我想applyAndTruncate隐藏在外面的世界(也就是说,来自Scoring模块之外的任何东西),因为我真的只把它作为主干bestKPercent和worstKPercent.有可能隐藏它吗?如果没有,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
Run Code Online (Sandbox Code Playgroud)
Ste*_*sen 12
您还可以使用签名文件来指定相应实现文件的公共接口.然后,我们的想法是,在实施固化之前,您不必担心可访问性.老实说,我从来没有使用它们,但它们被广泛用于F#编译器源代码(可能只是因为我对其他语言中使用的实现网站风格感到满意,而具有原始ML经验的人会很放心使用签名文件;此外,您还可以使用签名文件获得一些额外的功能,但没有什么超级引人注目的.
因此,如果您的Scoring模块是在一个名为的文件中实现的Scoring.fs,那么您将拥有一个相应的签名文件,其名称Scoring.fsi类似于:
namespace NS //replace with you actual namespace; I think you must use explicit namespaces
module Scoring =
//replace int[] with the actual ScoredPopulation type; I don't think you can use aliases
val bestKPercent : (float -> int[] -> int[])
val worstKPercent : (float -> int[] -> int[])
Run Code Online (Sandbox Code Playgroud)