In F #, whatever I want to see is quite standard abstract datatype:
Code inside the module is aware that my_Type is an int, but does not code outside, however, F # seems to be a restriction, where typed signatures can not be specifically hidden by a signature. This code returns a compiler error, and the restriction is described.If my_Type was a discriminating organization, then there is no compiler error. My question is, why restriction? I remember that it is capable of doing SML and OK, and besides, is it not perfect, when an intangible datatype is created? As Ganesh explains, it is a technical limit of F # compiler (and .NET runtime) as
thanks
let's (a: MyType): MyType = a + 1
the compiler A .NET method will be compiled with the following signature:
int foo (int a);
If the actual type of abbreviation was hidden from the users of the library, then they would not be able to assume that the foo
function is actually working MyType With
(This information is probably stored in some F # -specific meta-data, but it is not available for other .NET languages ...).
Perhaps the best solution for this marginalization is to define a type of discriminating union:
type MyType = MT int int let foo (MT a) = MT (A + 1)
Working with this type is quite convenient It adds some overhead (this type of New items are created while building value), but in most cases it should not be a big issue.
Comments
Post a Comment