gadt constructor
"Sébastien Dailly [email protected] [ocaml_beginners]" <[email protected]> Mon, 04 Jul 2016 17:34:19 +0200
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
Hello everybody,
I'm trying to convert a structure data into gadt, and do not know how to
build them :
Here is a little example :
(* The gadt I want to build *)
type _ data =
| Num : int -> int data
| Str : string -> string data
type values = [
| `Num of int
| `Other
]
(* Build the gadt *)
let builder : type a. values -> a data = begin function
| `Num n -> Num n
| _ -> Str ""
end
But this gives me an error :
Error: This expression has type int data
but an expression was expected of type a data
Type int is not compatible with type a
Do you know how I can tell the compiler that the type is polymorphic ?
Thanks a lot