module Before_ocaml_3_06 = struct class foo = object method foo = () end class foo' = object inherit foo method foo' = () end class on_any_foo = object method with_foo : foo -> unit = fun foo -> foo#foo end class ['foo] on_that_foo = object method with_foo : 'foo -> unit = fun foo -> foo#foo end class on_foo = [foo ] on_that_foo class on_foo' = [foo'] on_that_foo let _ = let foo = new foo in let foo' = new foo' in let on_any_foo = new on_any_foo in let on_foo = new on_foo in let on_foo' = new on_foo' in on_any_foo #with_foo (foo' :> foo) ; (* explicit subtyping *) on_foo #with_foo (foo' :> foo) ; (* explicit subtyping *) on_foo' #with_foo foo' ; () end module Ocaml_3_06 = struct class foo = object method foo = () end class foo' = object inherit foo method foo' = () end class on_any_foo = object method with_foo : 'a. (#foo as 'a) -> unit = fun foo -> foo#foo end class ['foo] on_that_foo = object method with_foo : 'foo -> unit = fun foo -> foo#foo (* could be something like: *) (* method with_foo : 'a. (#'foo as 'a) -> unit = fun foo -> foo#foo *) (* and calling: [foo] on_that_foo *) (* method with_foo : 'a. ('foo as 'a) -> unit = fun foo -> foo#foo *) (* and calling: [#foo] on_that_foo *) end class on_foo = [foo ] on_that_foo class on_foo' = [foo'] on_that_foo let _ = let foo = new foo in let foo' = new foo' in let on_any_foo = new on_any_foo in let on_foo = new on_foo in let on_foo' = new on_foo' in on_any_foo #with_foo foo' ; (* implicit subtyping *) on_foo #with_foo (foo' :> foo) ; (* explicit subtyping *) on_foo' #with_foo foo' ; () end