This works for me, for example, I get the output:
λ. \ SO180207.exe
Add 10
Add 5
Add 5
[||]
You can see Add 10 printed. In addition, when I accessed the internal module, both the value and the printfn "%A" operator printfn "%A" .
This is the project structure:
MyModule.fs file:
module internal MyModule.Types type Action = | Add of int | Update of int * string | Delete of string let x = Add 5 printfn "%A" x
Program.fs file:
module MyModule.Program open MyModule.Types [<EntryPoint>] let main argv = let x = Add 10 printfn "%A" x // prints Add 10 printfn "%A" MyModule.Types.x // prints Add 5 twice printfn "%A" argv 0 // return an integer exit code
So, perhaps you can provide more information about the F # version and the environment in which you work. It is also possible override x.ToString() inside your type.
Additional comment:
Honestly, there might be something with internal modules, as if I were redefining ToString() , the internal module is clearly not like it, and ends up with a StackOverFlowException . For instance. this works without the internal modifier:
module MyModule.Types type Action = | Add of int | Update of int * string | Delete of string override x.ToString() = sprintf "%A" (x,x) let x = Add 5 printfn "%A" x printfn "%A" (x.ToString()) |> ignore
λ. \ SO180207.exe
Add 10
Add 5
"(Add 5, Add 5)"
Add 5
[||]
source share