I’m trying to create a class and a method in it. For C# and VB, the CodeDom providers emit preditable output, but the F# CodeDom provider emits the following. I’m wondering why.
exception ReturnException8abef2fbb2404165b4b8690157bd3a49 of obj
exception ReturnNoneException8abef2fbb2404165b4b8690157bd3a49
type
// Hello
test = class
new() as this =
{
}
abstract my_method : unit -> unit
default this.my_method () =
()
end
Ignoring the exception stuff (I guess the provider is still a bit buggy), I’m curious as to why I get such a weird definition with new() as this, an abstract method and a default implementation. Am I missing something here?
The code generated by the CodeDOM generator is weird, but it is mostly valid F# code that compiles. As kvb points out, the definition of constructor is valid. It would be nicer if the CodeDOM provider generated code using implicit syntax, but that wouldn’t work well if you had multiple constructors.
As for the exceptions, these are used to emulate imperative
returnconstruct (as in C#). For example, you cannot directly write the following in F#:So the CodeDOM generator uses exception to emulate
returnandtry .. withto handle it.The usual coding style in F# is simply a bit different from C#/VB and the CodeDOM data structures were designed mainly for C#/VB. If you want to generate nice F# code, then writing your own code generator may be a better idea. Alternatively, someone could create F# CodeDOM provider that wouldn’t support all features, but would generate nice code.