summaryrefslogtreecommitdiff
path: root/lib/ur/listPair.ur
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2020-05-30 19:49:56 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2020-05-30 19:49:56 -0400
commitc2f1e1096f602b1cbd4531352f3e1ea6d656a186 (patch)
treeae102982878bb0c31bdfe07209e60bfc14030490 /lib/ur/listPair.ur
parent095c2640aa2070ed4e2765875238d5e6e6673856 (diff)
parent5a0b639dfbd7db9d16c6995f72ba17152a1f362d (diff)
Merge branch 'upstream' into dfsg_clean20200209+dfsgdfsg_clean
Diffstat (limited to 'lib/ur/listPair.ur')
-rw-r--r--lib/ur/listPair.ur26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/ur/listPair.ur b/lib/ur/listPair.ur
index 94b92872..52c73cd8 100644
--- a/lib/ur/listPair.ur
+++ b/lib/ur/listPair.ur
@@ -40,7 +40,31 @@ 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
+
+fun unzip [a] [b] (ls : list (a * b)) : list a * list b =
+ let
+ fun unzip' ls ls1 ls2 =
+ case ls of
+ [] => (List.rev ls1, List.rev ls2)
+ | (x1, x2) :: ls => unzip' ls (x1 :: ls1) (x2 :: ls2)
+ in
+ unzip' ls [] []
+ end