changeset 1884:5c30eea7aa78

ListPair.map2, based on code by escalier@riseup.net
author Adam Chlipala <adam@chlipala.net>
date Sun, 03 Nov 2013 19:27:30 -0500
parents 5125b1df6045
children 8297968cf7ef
files lib/ur/listPair.ur lib/ur/listPair.urs tests/listpair.ur tests/listpair.urp
diffstat 4 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <xml>ListPair.map2: Unequal list lengths</xml>
+    in
+        map2'
+    end
--- 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
--- /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 <xml>
+  {[ListPair.map2 plus x y]}
+</xml>
--- /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