Skip to content

Instantly share code, notes, and snippets.

@alinpopa
Created June 25, 2018 19:40
Show Gist options
  • Save alinpopa/3dd8086f295f956675154c0cb3672516 to your computer and use it in GitHub Desktop.
Save alinpopa/3dd8086f295f956675154c0cb3672516 to your computer and use it in GitHub Desktop.
OCaml GADTs to ReasonML
/* ReasonML equivalent to OCaml's GADTs:
type 'a t =
| Array : 'a array -> 'a t
| Bytes : bytes -> char t
let length (type el) (t:el t) = match t with
| Bytes b -> Bytes.length b
| Array a -> Array.length a
*/
type t('a) =
| Array(array('a)): t('a)
| Bytes(bytes): t(char);
let length (type el, t: t(el)) =
switch (t) {
| Array(x) => Array.length(x)
| Bytes(b) => Bytes.length(b)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment