I came across this implementation of a deque:
type 'a elem = { mutable l1 : 'a elem; mutable l2 : 'a elem; v : 'a option }
type 'a queue = { mutable front : 'a elem; mutable back : 'a elem }
let init () =
let rec g1 = { l1 = g1; l2 = g2; v = None}
and g2 = { l1 = g2; l2 = g1; v = None}
in
{ front = g1; back = g2 }
let is_empty q =
let f = q.front
and b = q.back
in
f.l2 == b
let put_between p q x =
let r = { l1 = p; l2 = q; v = Some x }
in begin
if p.l1 == q then p.l1 <- r else p.l2 <- r;
if q.l1 == p then q.l1 <- r else q.l2 <- r
end
I don't really understand what's the main idea of this realization, the main concept? Could you please explain it to me? Why are we using those records recursive to each other?