我正在嘗試學習oCaml,並且遇到問題,爲什麼下面的程序無效。基本OCaml OOP問題
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
是無效的。任何(我的意思是任何)幫助表示讚賞。
這不會破壞在myClass.doIt方法中使用結構類型的目的嗎? – Juliet 2009-01-26 00:12:24