summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-12-16 13:35:40 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2010-12-16 13:35:40 -0500
commit6aaa09dfff50fdd22aeef563de63a50926bb553f (patch)
treeed45e1d909672cac6d74d612f2c9531bb71681fa /lib
parentc7996285ff4b1b05a4cecdb2c1e944f7c17b18a7 (diff)
Fiddly tweaks
Diffstat (limited to 'lib')
-rw-r--r--lib/ur/list.ur13
-rw-r--r--lib/ur/list.urs1
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/ur/list.ur b/lib/ur/list.ur
index 354ef132..3153cc32 100644
--- a/lib/ur/list.ur
+++ b/lib/ur/list.ur
@@ -322,6 +322,19 @@ val nth [a] =
nth
end
+fun replaceNth [a] (ls : list a) (n : int) (v : a) : list a =
+ let
+ fun repNth (ls : list a) (n : int) (acc : list a) =
+ case ls of
+ [] => rev acc
+ | x :: ls' => if n <= 0 then
+ revAppend acc (v :: ls')
+ else
+ repNth ls' (n-1) (x :: acc)
+ in
+ repNth ls n []
+ end
+
fun assoc [a] [b] (_ : eq a) (x : a) =
let
fun assoc' (ls : list (a * b)) =
diff --git a/lib/ur/list.urs b/lib/ur/list.urs
index c23bf840..9ad738f1 100644
--- a/lib/ur/list.urs
+++ b/lib/ur/list.urs
@@ -72,6 +72,7 @@ val mapQueryPartialM : tables ::: {{Type}} -> exps ::: {Type} -> t ::: Type
val sort : a ::: Type -> (a -> a -> bool) (* > predicate *) -> t a -> t a
val nth : a ::: Type -> list a -> int -> option a
+val replaceNth : a ::: Type -> list a -> int -> a -> list a
(** Association lists *)