diff options
author | Adam Chlipala <adam@chlipala.net> | 2010-12-16 13:35:40 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2010-12-16 13:35:40 -0500 |
commit | 5c2db41e18a2b7a65452d3cecf13e3bc1886f863 (patch) | |
tree | ed45e1d909672cac6d74d612f2c9531bb71681fa /lib/ur/list.ur | |
parent | b064753122a284177a8ac0bad7b0f75bc300eb39 (diff) |
Fiddly tweaks
Diffstat (limited to 'lib/ur/list.ur')
-rw-r--r-- | lib/ur/list.ur | 13 |
1 files changed, 13 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)) = |