Guest User

Untitled

a guest
Jun 7th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.35 KB | None | 0 0
  1. type list = Nil | Cons of cell
  2.   and cell = {hd : int; mutable tl : list};;
  3.  
  4. let build_list f n = (* let's assume that always n > 0 *)
  5.   let cl = { hd = f (); tl = Nil } in
  6.   let res : list = Cons cl in
  7.   let cur = ref cl in
  8.   for i = 2 to n do
  9.     let c = { hd = f (); tl = Nil } in
  10.     (!cur).tl <- Cons c;
  11.     cur := c;
  12.   done;
  13.   res;;
Advertisement
Add Comment
Please, Sign In to add comment