Add constraints to typechecker, fix old tests, add new ones

This commit is contained in:
Gaith Hallak
2022-06-13 21:37:00 +04:00
parent f56eeb0b2b
commit 69713036d0
9 changed files with 383 additions and 14 deletions
+5 -3
View File
@@ -29,9 +29,11 @@ namespace List =
[] => abort("drop_last_unsafe: list empty")
function contains(e : 'a, l : list('a)) = switch(l)
[] => false
h::t => h == e || contains(e, t)
function
contains : 'a is eq; ('a, list('a)) => bool
contains(e, l) = switch(l)
[] => false
h::t => h == e || contains(e, t)
/** Finds first element of `l` fulfilling predicate `p` as `Some` or `None`
* if no such element exists.
+3 -1
View File
@@ -30,7 +30,9 @@ namespace Option =
None => abort(err)
Some(x) => x
function contains(e : 'a, o : option('a)) = o == Some(e)
function
contains : 'a is eq; ('a, option('a)) => bool
contains(e, o) = o == Some(e)
function on_elem(o : option('a), f : 'a => unit) : unit = match((), f, o)
+1
View File
@@ -90,6 +90,7 @@ namespace String =
Some(ix)
private function
is_prefix : (list(char), list(char)) => option(list(char))
is_prefix([], ys) = Some(ys)
is_prefix(_, []) = None
is_prefix(x :: xs, y :: ys) =