Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created August 5, 2018 22:57
Show Gist options
  • Save zerobias/002584c10ad49fb7035c3f282c373731 to your computer and use it in GitHub Desktop.
Save zerobias/002584c10ad49fb7035c3f282c373731 to your computer and use it in GitHub Desktop.
Use cases for GADT in OCaml/Reason
type typ(_) =
| Int: typ(int)
| String: typ(string)
| Pair(typ('a), typ('b)): typ(('a, 'b));
let rec to_string: type t. (typ(t), t) => string =
(t, x) =>
switch (t) {
| Int => string_of_int(x)
| String =>
Js.log(x);
x;
| Pair(t1, t2) =>
let (x1, x2) = x;
let text = "(" ++ to_string(t1, x1) ++ "," ++ to_string(t2, x2) ++ ")";
Js.log(text);
text;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment