# HG changeset patch # User Adam Chlipala # Date 1383524850 18000 # Node ID 5c30eea7aa787b21f089df327fbdaf8a30fe2bca # Parent 5125b1df6045ebd7c001bbd631aa2509602961d5 ListPair.map2, based on code by escalier@riseup.net diff -r 5125b1df6045 -r 5c30eea7aa78 lib/ur/listPair.ur --- a/lib/ur/listPair.ur Thu Oct 17 09:22:38 2013 -0400 +++ b/lib/ur/listPair.ur Sun Nov 03 19:27:30 2013 -0500 @@ -33,3 +33,14 @@ 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 ListPair.map2: Unequal list lengths + in + map2' + end diff -r 5125b1df6045 -r 5c30eea7aa78 lib/ur/listPair.urs --- a/lib/ur/listPair.urs Thu Oct 17 09:22:38 2013 -0400 +++ b/lib/ur/listPair.urs Sun Nov 03 19:27:30 2013 -0500 @@ -5,3 +5,6 @@ -> (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 -r 5125b1df6045 -r 5c30eea7aa78 tests/listpair.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/listpair.ur Sun Nov 03 19:27:30 2013 -0500 @@ -0,0 +1,6 @@ +val x = 1 :: 2 :: [] +val y = 3 :: 4 :: [] + +fun main () : transaction page = return + {[ListPair.map2 plus x y]} + diff -r 5125b1df6045 -r 5c30eea7aa78 tests/listpair.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/listpair.urp Sun Nov 03 19:27:30 2013 -0500 @@ -0,0 +1,5 @@ +rewrite all Listpair/* + +$/list +$/listPair +listpair