Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module SafeList = {
- type empty =
- | Empty;
- type nonEmpty =
- | NonEmpty;
- type t('a, 's) =
- | []: t('a, empty)
- | ::(('a, t('a, 's))): t('a, nonEmpty);
- let rec length: type s. t(_, s) => int =
- fun
- | [] => 0
- | [h, ...t] => 1 + length(t);
- let head: type a. t(a, nonEmpty) => a =
- fun
- | [x, ..._] => x;
- let tail: t('a, nonEmpty) => t('a, nonEmpty) =
- fun
- | [a] => [a]
- | [a, b, ...tail] => [b, ...tail]
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement