comparison 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
comparison
equal deleted inserted replaced
1344:660a2715e2bd 1345:9e0fa4f6ac93
320 nth ls' (n-1) 320 nth ls' (n-1)
321 in 321 in
322 nth 322 nth
323 end 323 end
324 324
325 fun replaceNth [a] (ls : list a) (n : int) (v : a) : list a =
326 let
327 fun repNth (ls : list a) (n : int) (acc : list a) =
328 case ls of
329 [] => rev acc
330 | x :: ls' => if n <= 0 then
331 revAppend acc (v :: ls')
332 else
333 repNth ls' (n-1) (x :: acc)
334 in
335 repNth ls n []
336 end
337
325 fun assoc [a] [b] (_ : eq a) (x : a) = 338 fun assoc [a] [b] (_ : eq a) (x : a) =
326 let 339 let
327 fun assoc' (ls : list (a * b)) = 340 fun assoc' (ls : list (a * b)) =
328 case ls of 341 case ls of
329 [] => None 342 [] => None