# HG changeset patch # User Adam Chlipala # Date 1276452827 14400 # Node ID 4c367c8f5b2db28b799797612639b348523e673d # Parent cd8d2c73ccf4d7daab06e62ec687c11497a2da1e List.mapi diff -r cd8d2c73ccf4 -r 4c367c8f5b2d lib/ur/list.ur --- a/lib/ur/list.ur Sun Jun 13 14:13:06 2010 -0400 +++ b/lib/ur/list.ur Sun Jun 13 14:13:47 2010 -0400 @@ -101,6 +101,16 @@ mp' [] end +fun mapi [a] [b] f = + let + fun mp' n acc ls = + case ls of + [] => rev acc + | x :: ls => mp' (n + 1) (f n x :: acc) ls + in + mp' 0 [] + end + fun mapPartial [a] [b] f = let fun mp' acc ls = diff -r cd8d2c73ccf4 -r 4c367c8f5b2d lib/ur/list.urs --- a/lib/ur/list.urs Sun Jun 13 14:13:06 2010 -0400 +++ b/lib/ur/list.urs Sun Jun 13 14:13:47 2010 -0400 @@ -22,6 +22,8 @@ val mapPartial : a ::: Type -> b ::: Type -> (a -> option b) -> t a -> t b +val mapi : a ::: Type -> b ::: Type -> (int -> a -> b) -> t a -> t b + val mapX : a ::: Type -> ctx ::: {Unit} -> (a -> xml ctx [] []) -> t a -> xml ctx [] [] val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type