From f2882c39c1acb5abc16f49524acb08d6c0b7b1d5 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Fri, 7 Feb 2020 13:53:50 -0500 Subject: List.foldli --- 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 848bbd5f..1eb7626a 100644 --- a/lib/ur/list.ur +++ b/lib/ur/list.ur @@ -31,6 +31,16 @@ fun foldl [a] [b] (f : a -> b -> b) = foldl' end +fun foldli [a] [b] (f : int -> a -> b -> b) = + let + fun foldli' i acc ls = + case ls of + [] => acc + | x :: ls => foldli' (i + 1) (f i x acc) ls + in + foldli' 0 + end + val rev = fn [a] => let fun rev' acc (ls : list a) = diff --git a/lib/ur/list.urs b/lib/ur/list.urs index 6df2d5d9..f81f38a4 100644 --- a/lib/ur/list.urs +++ b/lib/ur/list.urs @@ -7,6 +7,8 @@ val foldl : a ::: Type -> b ::: Type -> (a -> b -> b) -> b -> t a -> b val foldlAbort : a ::: Type -> b ::: Type -> (a -> b -> option b) -> b -> t a -> option b val foldlMapAbort : a ::: Type -> b ::: Type -> c ::: Type -> (a -> b -> option (c * b)) -> b -> t a -> option (t c * b) +val foldli : a ::: Type -> b ::: Type + -> (int -> a -> b -> b) -> b -> t a -> b val foldr : a ::: Type -> b ::: Type -> (a -> b -> b) -> b -> t a -> b -- cgit v1.2.3