Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. module SafeList = {
  2. type empty =
  3. | Empty;
  4. type nonEmpty =
  5. | NonEmpty;
  6. type t('a, 's) =
  7. | []: t('a, empty)
  8. | ::(('a, t('a, 's))): t('a, nonEmpty);
  9. let rec length: type s. t(_, s) => int =
  10. fun
  11. | [] => 0
  12. | [h, ...t] => 1 + length(t);
  13. let head: type a. t(a, nonEmpty) => a =
  14. fun
  15. | [x, ..._] => x;
  16.  
  17. let tail: t('a, nonEmpty) => t('a, nonEmpty) =
  18. fun
  19. | [a] => [a]
  20. | [a, b, ...tail] => [b, ...tail]
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement