summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2020-02-07 13:53:50 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2020-02-07 13:53:50 -0500
commitf2882c39c1acb5abc16f49524acb08d6c0b7b1d5 (patch)
treecdc5caae9b7420a1eb14cdf724db4380a8e8257e
parentef4e0c207abd0e41badf7bf0052b498eb6c01d43 (diff)
List.foldli
-rw-r--r--lib/ur/list.ur10
-rw-r--r--lib/ur/list.urs2
2 files changed, 12 insertions, 0 deletions
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