4
考虑以下小OCaml的类层次结构:类方法可见细化
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 *)
我想实现的是细化领域class z
w.r.t.的x
class y
并有细化可见在z的类型,即
class z = object method x = (new x2 :> x) inherit y end;;
(new z)#x#j;; (* type error *)
是不我想达到的目标。
我相当有信心,有一种方法来说服细化的兼容性的类型检查,但如何?