I'd like to make applyAndTruncate
hidden from the outside world (that is, from anything outside the Scoring
module), as I really only use it as backbone for bestKPercent
and worstKPercent
. Is it possible to hide it? If not, what is the F#ish way of accomplishing what I want to do?
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
Yes. let private myfunc =
will do it.
You can also use signature files to specify the public interface of a corresponding implementation file. Then the idea is that you don't worry about accessibility until the implementation has solidified. I've honestly not ever used them, but they are used in the F# compiler source code extensively (probably just because I'm comfortable with the implementation site style used in so many other languages, whereas folks with original ML experience will be at ease with signature files; also, you do get some extra features with signature files, though nothing super compelling).
So if your Scoring
module were implemented in a file named Scoring.fs
, you'd have a corresponding signature file named Scoring.fsi
that would look something like:
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[])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With