I have following type definition of x
with a GADT.
type x = X : 'a option -> x
and I'm trying to write a function to get the value of option
accompanying with tag X
I first tried the following
let get = fun (X a)->a
and obtained the following error message
Error: This expression has type $X_'a option
but an expression was expected of type 'a
The type constructor $X_'a would escape its scope
secondly I tried this
let get : type a.x-> a option = fun (X a)->a
and following
Error: This expression has type $X_'a option
but an expression was expected of type a option
Type $X_'a is not compatible with type a
I think since the type 'a
given to the option
inside type x
doesn't appear in type annotation, there is no way to write what 'a
actually is in type annotation explicitly.