Ocaml has nothing like forward declarations (i.e. the promise that something will be defined in the end), but it has recursive definitions (i.e. a block of things that are declared and then immediately defined in terms of each friend). Recursive definitions are possible between expressions, types, classes, and modules (and more); mutually recursive modules allow you to recursively define mixed sets of objects.
You can solve your problem using a recursive definition with the and keyword:
class foo(x : bar) = object method f () = x#h () method g () = 0 end and bar(x : foo) = object method h () = x#g() end
source share