+ if l.head == nil then begin
+ l.head <- ncell;
+ l.last <- ncell;
+ l.length <- 1
+ end else begin
+ l.last.next <- ncell;
+ l.last <- ncell;
+ l.length <- l.length + 1
+ end
+
+let push_back n l = add n l
+let push_front n l =
+ let ncell = { node = n;
+ next = l.head }
+ in
+ if l.head == nil then begin
+ l.head <- ncell;
+ l.last <- ncell;
+ l.length <- 1;
+ end else begin
+ l.head <- ncell;
+ l.length <- l.length + 1;
+ end
+
+let head l = l.head
+let last l = l.last
+let next i = i.next
+let value i = i.node
+let finished i = i == nil
+
+let copy l =
+ let rec loop l2 i =
+ if finished i then l2 else begin
+ add (value i) l2;
+ loop l2 (next i)
+ end
+ in
+ loop (create ()) (head l)