summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ur/list.ur14
-rw-r--r--lib/ur/list.urs2
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/ur/list.ur b/lib/ur/list.ur
index 71d8fa98..354ef132 100644
--- a/lib/ur/list.ur
+++ b/lib/ur/list.ur
@@ -308,6 +308,20 @@ fun sort [a] (gt : a -> a -> bool) (ls : t a) : t a =
sort' ls
end
+val nth [a] =
+ let
+ fun nth (ls : list a) (n : int) : option a =
+ case ls of
+ [] => None
+ | x :: ls' =>
+ if n <= 0 then
+ Some x
+ else
+ nth ls' (n-1)
+ in
+ nth
+ 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 a0cec8fb..c23bf840 100644
--- a/lib/ur/list.urs
+++ b/lib/ur/list.urs
@@ -71,6 +71,8 @@ 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
+
(** Association lists *)
val assoc : a ::: Type -> b ::: Type -> eq a -> a -> t (a * b) -> option b