I have next code:
module MakeLink (Key : Map.OrderedType) = struct
module Links = Map.Make (Key)
type 'a t =
{ links : 'a t Links.t;
value : 'a
}
type key_t = Key.t
let make value =
{ links = Links.empty;
value
}
let link linker ~to':linkable ~by:key =
{ linker with links =
Links.add key linkable linker.links
}
(* some functions for reading here *)
end
How to create two links linked to each other? I tried:
let join a ~with':b ~by:key =
let rec a' = link a ~to':b' ~by:key
and b' = link b ~to':a' ~by:(Key.opposite key) in
a'
But it's looking like a hen that hatched from their own egg. And my question is: How to create graph with cycles (for example: doubly-linked list) without mutable data using (in OCaml or other language)?