From 5f341ee6866e51c5f528084d601678b91a0d6908 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 13 Jun 2010 14:13:47 -0400 Subject: List.mapi --- lib/ur/list.ur | 10 ++++++++++ lib/ur/list.urs | 2 ++ 2 files changed, 12 insertions(+) diff --git a/lib/ur/list.ur b/lib/ur/list.ur index bccbc82a..bb814714 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -101,6 +101,16 @@ fun mp [a] [b] f = 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 --git a/lib/ur/list.urs b/lib/ur/list.urs index 00c95053..7ce3c61f 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -22,6 +22,8 @@ val mp : a ::: Type -> b ::: Type -> (a -> b) -> t a -> t b 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 -- cgit v1.2.3