changeset 1539:dde3bd82cb3d

List.mapXi
author Adam Chlipala <adam@chlipala.net>
date Mon, 15 Aug 2011 10:22:09 -0400
parents ade93cd5bc59
children 659a2f71f5e5
files lib/ur/list.ur lib/ur/list.urs
diffstat 2 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ur/list.ur	Sun Aug 14 17:39:18 2011 -0400
+++ b/lib/ur/list.ur	Mon Aug 15 10:22:09 2011 -0400
@@ -133,6 +133,16 @@
         mapX'
     end
 
+fun mapXi [a] [ctx ::: {Unit}] f =
+    let
+        fun mapX' i ls =
+            case ls of
+                [] => <xml/>
+              | x :: ls => <xml>{f i x}{mapX' (i + 1) ls}</xml>
+    in
+        mapX' 0
+    end
+
 fun mapM [m ::: (Type -> Type)] (_ : monad m) [a] [b] f =
     let
         fun mapM' acc ls =
--- a/lib/ur/list.urs	Sun Aug 14 17:39:18 2011 -0400
+++ b/lib/ur/list.urs	Mon Aug 15 10:22:09 2011 -0400
@@ -26,6 +26,8 @@
 
 val mapX : a ::: Type -> ctx ::: {Unit} -> (a -> xml ctx [] []) -> t a -> xml ctx [] []
 
+val mapXi : a ::: Type -> ctx ::: {Unit} -> (int -> a -> xml ctx [] []) -> t a -> xml ctx [] []
+
 val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type
            -> (a -> m b) -> t a -> m (t b)