Added contains functions in List and Option. Fixed one type error catch

This commit is contained in:
radrow
2020-08-26 11:56:18 +02:00
parent ed5447e430
commit 7e32ef57c2
4 changed files with 32 additions and 7 deletions
+6 -2
View File
@@ -15,10 +15,14 @@ namespace List =
_::t => Some(t)
function last(l : list('a)) : option('a) = switch(l)
[] => None
[x] => Some(x)
[] => None
[x] => Some(x)
_::t => last(t)
function contains(e : 'a, l : list('a)) = 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.
*/
+4
View File
@@ -26,6 +26,10 @@ namespace Option =
None => abort("Forced None value")
Some(x) => x
function contains(e : 'a, o : option('a)) = switch(o)
None => false
Some(x) => x == e
function on_elem(o : option('a), f : 'a => unit) : unit = match((), f, o)
function map(f : 'a => 'b, o : option('a)) : option('b) = switch(o)