Created
June 25, 2018 19:40
-
-
Save alinpopa/3dd8086f295f956675154c0cb3672516 to your computer and use it in GitHub Desktop.
OCaml GADTs to ReasonML
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
/* 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