Created
October 27, 2011 09:25
-
-
Save klapaucius/1319152 to your computer and use it in GitHub Desktop.
map in ocaml
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
(* batList.ml *) | |
type 'a mut_list = { | |
hd: 'a; | |
mutable tl: 'a list | |
} | |
external inj : 'a mut_list -> 'a list = "%identity" | |
let map f = function | |
| [] -> [] | |
| h :: t -> | |
let rec loop dst = function | |
| [] -> () | |
| h :: t -> | |
let r = { hd = f h; tl = [] } in | |
dst.tl <- inj r; | |
loop r t | |
in | |
let r = { hd = f h; tl = [] } in | |
loop r t; | |
inj r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment