I have declared a type in F# that i now want to consume in C#. The type definition is:
type ConstObj = {value:int;}
type Instruction =
| CONST of ConstObj
| HALT
I can successfully pattern match CONST Instruction but can't match HALT as the compiler throws an error during compilation saying "CS0426 The type name 'HALT' does not exist in the type 'Types.Instruction'"
private void Eval(Instruction instruction) {
switch (instruction) {
case Instruction.CONST c:
break;
case Instruction.HALT h:
break;
default:
break;
}
}
But the same type can be successfully pattern matched in F#:
let matcher x =
match x with
| Instruction.CONST{value=v;} ->
printfn "Const instruction. Value is %i" v
| Instruction.HALT ->
printfn "HALT instruction"
Any ideas?