As people said, F # does not currently support nested classes.
One way around this, as shown by VB, is with two separate classes, one of which is private.
However, if the inner class is simple (with only one or two methods), then there is an alternative approach that should use closure as an object for poor people .
In the code below, the KnownParsing function creates two functions and returns them as a pair. knownParsingSet then contains function pairs, not class instances.
If there is only one method in a nested class, then this approach is great, because one method class is basically just a function. For more than one method in a nested class, it gets pretty ugly, which is why F # people have a problem using other methods. :)
type KnownRuleGoals() = let knownParsingSet = System.Collections.Generic.HashSet() // use a function let KnownParsing() = let knownParsing = [||] let doWork() = () // do something let doWork2() = () // do something // return the pair of functions doWork,doWork2 // the member/method comes after the closure because // definitions must come before usage. member this.record() = knownParsingSet.Add(KnownParsing())
source share