Created
October 2, 2017 05:14
-
-
Save kunigami/bce04539438e19ea7787cc69645d1bcb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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