小编Dav*_*ind的帖子

使用其他方法制作Ocaml子类的正确方法是什么?

在Ocaml中,我正在努力进行子类化和类型化:

class super =  
  object (self)  
  method doIt =   
    ...  
end;  

class sub =  
  object (self)  
  inherit super  
  method doIt =   
    ...  
    self#somethingElse  
    ...  

  method somethingElse =  
    ...  
end;  

let myFunction (s:super) =  
  ...  

myFunction new sub
Run Code Online (Sandbox Code Playgroud)

显然OCaml中,阶级sub不是一类的"子" super,因为该sub#doIt方法调用的方法sub是不存在的super.但是,这似乎是OO编程的一个非常常见的用例.推荐的方法是什么?

inheritance ocaml types class object

8
推荐指数
2
解决办法
1308
查看次数

标签 统计

class ×1

inheritance ×1

object ×1

ocaml ×1

types ×1