考虑以下小的 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 *)
我想要实现的是细化wrt的领域x
,并在 z 的类型上看到细化,即class z
class y
class z = object method x = (new x2 :> x) inherit y end;;
(new z)#x#j;; (* type error *)
不是我想要达到的。
我非常有信心有一种方法可以说服类型检查器对改进的兼容性,但是如何呢?