summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2013-11-03 19:27:30 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2013-11-03 19:27:30 -0500
commitd2196dbd5c4379bdbc307d2035c8a07ef09b592d (patch)
tree03de0d970495a013a2e126010600137ebb5746dd
parent65b818146effe2f74192a3b1d65b4ec792a8a350 (diff)
ListPair.map2, based on code by escalier@riseup.net
-rw-r--r--lib/ur/listPair.ur11
-rw-r--r--lib/ur/listPair.urs3
-rw-r--r--tests/listpair.ur6
-rw-r--r--tests/listpair.urp5
4 files changed, 25 insertions, 0 deletions
diff --git a/lib/ur/listPair.ur b/lib/ur/listPair.ur
index 0182af19..d69993f9 100644
--- a/lib/ur/listPair.ur
+++ b/lib/ur/listPair.ur
@@ -33,3 +33,14 @@ fun all [a] [b] f =
in
all'
end
+
+fun map2 [a] [b] [c] (f : a -> b -> c) =
+ let
+ fun map2' ls1 ls2 =
+ case (ls1, ls2) of
+ ([], []) => []
+ | (x1 :: ls1, x2 :: ls2) => f x1 x2 :: map2' ls1 ls2
+ | _ => error <xml>ListPair.map2: Unequal list lengths</xml>
+ in
+ map2'
+ end
diff --git a/lib/ur/listPair.urs b/lib/ur/listPair.urs
index f2287c13..218b9420 100644
--- a/lib/ur/listPair.urs
+++ b/lib/ur/listPair.urs
@@ -5,3 +5,6 @@ val mapX : a ::: Type -> b ::: Type -> ctx ::: {Unit}
-> (a -> b -> xml ctx [] []) -> list a -> list b -> xml ctx [] []
val all : a ::: Type -> b ::: Type -> (a -> b -> bool) -> list a -> list b -> bool
+
+val map2 : a ::: Type -> b ::: Type -> c ::: Type
+ -> (a -> b -> c) -> list a -> list b -> list c
diff --git a/tests/listpair.ur b/tests/listpair.ur
new file mode 100644
index 00000000..4ecacfd3
--- /dev/null
+++ b/tests/listpair.ur
@@ -0,0 +1,6 @@
+val x = 1 :: 2 :: []
+val y = 3 :: 4 :: []
+
+fun main () : transaction page = return <xml>
+ {[ListPair.map2 plus x y]}
+</xml>
diff --git a/tests/listpair.urp b/tests/listpair.urp
new file mode 100644
index 00000000..1b447ed6
--- /dev/null
+++ b/tests/listpair.urp
@@ -0,0 +1,5 @@
+rewrite all Listpair/*
+
+$/list
+$/listPair
+listpair