From 096fbda34b67cccd2026c44006bd9bc98d28c98c Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Sun, 4 Nov 2018 09:39:07 -0500 Subject: List.mapMi --- lib/ur/list.ur | 10 ++++++++++ lib/ur/list.urs | 3 +++ 2 files changed, 13 insertions(+) (limited to 'lib') diff --git a/lib/ur/list.ur b/lib/ur/list.ur index d28d2868..0da9316e 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -153,6 +153,16 @@ fun mapM [m ::: (Type -> Type)] (_ : monad m) [a] [b] f = mapM' [] end +fun mapMi [m ::: (Type -> Type)] (_ : monad m) [a] [b] f = + let + fun mapM' i acc ls = + case ls of + [] => return (rev acc) + | x :: ls => x' <- f i x; mapM' (i + 1) (x' :: acc) ls + in + mapM' 0 [] + end + fun mapPartialM [m ::: (Type -> Type)] (_ : monad m) [a] [b] f = let fun mapPartialM' acc ls = diff --git a/lib/ur/list.urs b/lib/ur/list.urs index f4593dda..c5c279b7 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -31,6 +31,9 @@ val mapXi : a ::: Type -> ctx ::: {Unit} -> (int -> a -> xml ctx [] []) -> t a - val mapM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type -> (a -> m b) -> t a -> m (t b) +val mapMi : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type + -> (int -> a -> m b) -> t a -> m (t b) + val mapPartialM : m ::: (Type -> Type) -> monad m -> a ::: Type -> b ::: Type -> (a -> m (option b)) -> t a -> m (t b) val mapXM : m ::: (Type -> Type) -> monad m -> a ::: Type -> ctx ::: {Unit} -- cgit v1.2.3