type 'a mylist = 'a listcell ref
and 'a listcell = Nil | Cons of 'a * ('a mylist)
let l1 = (ref (Cons (1, ref (Cons (2,ref Nil)))))
let l2 = (ref (Cons(3, ref (Cons(4, ref Nil)))))
let rec append l1 l2 =
match l1 with
| {contents = Nil} -> (l1 := !l2; l1)
| {contents = Cons(h,t)} -> append t l2
这就是我到目前为止所得到的,目标是将 l2 附加到 l1 我可以遍历到 l1 的末尾并用 l2 替换 ref ......这就是我想要做的。但由于某种原因,我失去了在那之前的一切。
任何帮助将不胜感激,谢谢