Created
August 5, 2018 22:57
-
-
Save zerobias/002584c10ad49fb7035c3f282c373731 to your computer and use it in GitHub Desktop.
Use cases for GADT in OCaml/Reason
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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