Skip to content

Instantly share code, notes, and snippets.



Created Oct 2, 2017
What would you like to do?
let rec fupdate: 'a. ('a -> 'a) -> int -> 'a seq -> 'a seq =
fun updater index digits -> match (index, digits) with
| (index, Nil) -> raise IndexOutOfBoundsException
| (0, One (elem, restDigits)) -> One (updater elem, restDigits)
| (index, One (elem, restDigits)) ->
push elem (fupdate updater (index - 1) (Zero restDigits))
| (index, Zero restDigits) ->
let updater' = fun (x, y) -> if index mod 2 == 0
then (updater x, y)
else (x, updater y)
in Zero (fupdate updater' (index / 2) restDigits)
let rec update index element digits =
fupdate (fun x -> element) index digits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.