F# Private Static Methods
-
06-07-2019 - |
Question
How do i define a private static method in a class in f#? when i try to attach a private modifier it complains.
Solution
Here's a short script that defines and uses a private static member:
type MyClass =
static member private MyPrivateMember() = printfn "MyPrivateMember()"
static member MyMember() = MyClass.MyPrivateMember()
MyClass.MyMember() // MyPrivateMember()
OTHER TIPS
An alternative:
type MyClass () =
static let myPrivateMethod () =
printfn "This is inaccessible outside the class."
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow