diff options
author | Adam Chlipala <adam@chlipala.net> | 2018-12-31 14:48:16 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2018-12-31 14:48:16 -0500 |
commit | 4ada57be570bfbe18137c5b37ed5e0d327de82db (patch) | |
tree | 94781877bfd974d64ba9fc4d6fd223e4125c29b9 | |
parent | 7340651c636cb3fc1fde05cb4ae0db95e6716f2c (diff) |
ListPair.mapM
-rw-r--r-- | lib/ur/listPair.ur | 16 | ||||
-rw-r--r-- | lib/ur/listPair.urs | 3 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/ur/listPair.ur b/lib/ur/listPair.ur index 94b92872..c5e70708 100644 --- a/lib/ur/listPair.ur +++ b/lib/ur/listPair.ur @@ -40,7 +40,21 @@ fun mp [a] [b] [c] (f : a -> b -> c) = case (ls1, ls2) of ([], []) => [] | (x1 :: ls1, x2 :: ls2) => f x1 x2 :: map' ls1 ls2 - | _ => error <xml>ListPair.map2: Unequal list lengths</xml> + | _ => error <xml>ListPair.mp: Unequal list lengths</xml> in map' end + +fun mapM [m] (_ : monad m) [a] [b] [c] (f : a -> b -> m c) = + let + fun mapM' ls1 ls2 = + case (ls1, ls2) of + ([], []) => return [] + | (x1 :: ls1, x2 :: ls2) => + y <- f x1 x2; + ls <- mapM' ls1 ls2; + return (y :: ls) + | _ => error <xml>ListPair.mapM: Unequal list lengths</xml> + in + mapM' + end diff --git a/lib/ur/listPair.urs b/lib/ur/listPair.urs index b473e226..9efff405 100644 --- a/lib/ur/listPair.urs +++ b/lib/ur/listPair.urs @@ -8,3 +8,6 @@ val all : a ::: Type -> b ::: Type -> (a -> b -> bool) -> list a -> list b -> bo val mp : a ::: Type -> b ::: Type -> c ::: Type -> (a -> b -> c) -> list a -> list b -> list c + +val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type -> c ::: Type + -> (a -> b -> m c) -> list a -> list b -> m (list c) |