module internal MyModule
type MyChar =
| Char of char
static member op_Explicit(myChar): char =
match myChar with
| Char c -> c
module MyCharTest =
[<EntryPoint>]
let main _ =
let mc = Char 'F'
printfn "%A" mc
let c = char mc // error FS0001: The type 'MyChar' does not support a conversion to the type 'char'
printfn "%c" c
0
If I remove internal
keyword from the first line, it compiles and runs well. Why can’t I call the explict operator defined in the type contained in the internal
module?
For comparison, the following equivalent C# program compiles without an error:
using System;
internal class MyClass {
class MyChar {
char _mc;
public MyChar(char c) => _mc = c;
public static explicit operator char(MyChar myChar) => myChar._mc;
}
class MyCharTest {
static void Main() {
var mc = new MyChar('C');
char c = (char)mc;
Console.WriteLine(c);
}
}
}