diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-06-09 11:12:34 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-06-09 11:12:34 -0400 |
commit | b64c799498c352096f89e1e0ab7a75ab14565d3a (patch) | |
tree | afab9c1f2b021be1afaaac75f504977531d52f6b /lib | |
parent | 3d7820916ae84710cab458c6b4ba9b1412ee3f5d (diff) |
Mark current as effectful; add List functions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ur/list.ur | 43 | ||||
-rw-r--r-- | lib/ur/list.urs | 11 |
2 files changed, 38 insertions, 16 deletions
diff --git a/lib/ur/list.ur b/lib/ur/list.ur index 60cd7316..2e62facb 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -10,6 +10,16 @@ val show = fn [a] (_ : show a) => mkShow show' end +fun foldl [a] [b] f = + let + fun foldl' acc ls = + case ls of + [] => acc + | x :: ls => foldl' (f x acc) ls + in + foldl' + end + val rev = fn [a] => let fun rev' acc (ls : list a) = @@ -123,20 +133,6 @@ fun foldlMap [a] [b] [c] f = fold [] end -fun assoc [a] [b] (_ : eq a) (x : a) = - let - fun assoc' ls = - case ls of - [] => None - | (y, z) :: ls => - if x = y then - Some z - else - assoc' ls - in - assoc' - end - fun search [a] [b] f = let fun search' ls = @@ -183,3 +179,22 @@ fun app [m] (_ : monad m) [a] f = in app' end + +fun assoc [a] [b] (_ : eq a) (x : a) = + let + fun assoc' (ls : list (a * b)) = + case ls of + [] => None + | (y, z) :: ls => + if x = y then + Some z + else + assoc' ls + in + assoc' + end + +fun assocAdd [a] [b] (_ : eq a) (x : a) (y : b) (ls : t (a * b)) = + case assoc x ls of + None => (x, y) :: ls + | Some _ => ls diff --git a/lib/ur/list.urs b/lib/ur/list.urs index 7906970a..daf81074 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -2,6 +2,8 @@ datatype t = datatype Basis.list val show : a ::: Type -> show a -> show (list a) +val foldl : a ::: Type -> b ::: Type -> (a -> b -> b) -> b -> t a -> b + val rev : a ::: Type -> t a -> t a val revAppend : a ::: Type -> t a -> t a -> t a @@ -30,11 +32,16 @@ val foldlM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type val foldlMap : a ::: Type -> b ::: Type -> c ::: Type -> (a -> b -> c * b) -> b -> t a -> t c * b -val assoc : a ::: Type -> b ::: Type -> eq a -> a -> t (a * b) -> option b - val search : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> option b val all : a ::: Type -> (a -> bool) -> t a -> bool val app : m ::: (Type -> Type) -> monad m -> a ::: Type -> (a -> m unit) -> t a -> m unit + + +(** Association lists *) + +val assoc : a ::: Type -> b ::: Type -> eq a -> a -> t (a * b) -> option b + +val assocAdd : a ::: Type -> b ::: Type -> eq a -> a -> b -> t (a * b) -> t (a * b) |