consider the following small ocaml class hierarchy:
class x = object method i = 0 end ;;
class y = object method x = new x end ;;
class x2 = object method i = 0 method j = 1 end ;;
class z = object method x = new x2 inherit y end;; (* type error *)
What I want to achieve is to refine the field x
of class z
w.r.t. class y
and have that refinement visible at the type of z, i.e.
class z = object method x = (new x2 :> x) inherit y end;;
(new z)#x#j;; (* type error *)
is not what I want to achieve.
I am pretty confident that there is a way to convinve the type checker of the compatibility of the refinement, but how?