diff lib/ur/list.ur @ 1345:9e0fa4f6ac93

Fiddly tweaks
author Adam Chlipala <adam@chlipala.net>
date Thu, 16 Dec 2010 13:35:40 -0500
parents 80bff6449f41
children d328983dc5a6
line wrap: on
line diff
--- a/lib/ur/list.ur	Thu Dec 16 10:23:37 2010 -0500
+++ b/lib/ur/list.ur	Thu Dec 16 13:35:40 2010 -0500
@@ -322,6 +322,19 @@
         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)) =