我正在尝试学习 oCaml,但我对以下程序无效的原因有疑问。
class myClass2 =
object
method doSomething = Printf.printf "%s\n" "Doing something"
end;;
class myClass foo =
object
val dMember = foo
method doIt = dMember#doSomething
end;;
let mc2 = new myClass2;;
let mc = new myClass mc2;;
mc#doIt;;
我在尝试编译程序时收到的错误是:
File "sample.ml", line 6, characters 5-84:
Some type variables are unbound in this type:
class myClass :
(< doSomething : 'b; .. > as 'a) ->
object val dMember : 'a method doIt : 'b end
The method doIt has type 'a where 'a is unbound
我对为什么特别感兴趣:
val dMember = foo
method doIt = dMember#doSomething
是无效的。感谢任何(我的意思是任何)帮助。