Objects are normal expressions in OCaml, so you can pass them as arguments to the constructor of objects and classes. See the section in the OCaml manual for a deeper explanation.
So, for example, you can write:
class node (name : string) = object
method name = name
end
class link (previous : node) (next : node) = object
method previous = previous
method next = next
end
let () =
let n1 = new node "n1" in
let n2 = new node "n2" in
let l = new link n1 n2 in
Printf.printf "'%s' -> '%s'\n" l
source
share