Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type list = Nil | Cons of cell
- and cell = {hd : int; mutable tl : list};;
- let build_list f n = (* let's assume that always n > 0 *)
- let cl = { hd = f (); tl = Nil } in
- let res : list = Cons cl in
- let cur = ref cl in
- for i = 2 to n do
- let c = { hd = f (); tl = Nil } in
- (!cur).tl <- Cons c;
- cur := c;
- done;
- res;;
Advertisement
Add Comment
Please, Sign In to add comment