Created
January 19, 2019 06:39
-
-
Save wokalski/46662bd6e4fbeb3ad3223c25165986ee to your computer and use it in GitHub Desktop.
This file contains 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 t('list, 'last) = | |
| []: t('a, 'a) | |
| ::('a, t('l, 't)): t('a => 'l, 't); | |
let rec (@): | |
type start mid rest. (t(start, mid => rest), mid) => t(start, rest) = | |
(l, r) => | |
switch (l) { | |
| [] => [r] | |
| [a, ...q] => [a, ...q @ r] | |
}; | |
let split: type a b. t(a => b, unit) => (a, t(b, unit)) = | |
fun | |
| [a, ...q] => (a, q) | |
let use: | |
type a value start rest. | |
(option(t(value => a, unit)), value, t(start, value => rest)) => | |
(value, t(start, rest), option(t(a, unit))) = | |
(hooks, default, nextHooks) => | |
switch (hooks) { | |
| Some(hooks) => | |
let (value, rest) = split(hooks); | |
(value, nextHooks @ value, Some(rest)); | |
| None => (default, nextHooks @ default, None) | |
}; | |
{ | |
let initl = ["a", 0]; | |
let l = Some(initl); | |
let nextl = []; | |
let (_da_value, nextl, l) = use(l, "1", nextl); | |
let (_da_value, nextl, _) = use(l, 2, nextl); | |
let res = string_of_bool(initl == nextl); /* true */ | |
print_endline(res); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment