トップレベルではなく、コンパイルされたコードを使用して OCaml を学習しようとしています。ただし、オンラインのサンプル コードの多くは後者にアピールしているようです。
以下のオブジェクトのメソッド内に新しい Foo を作成したいと思います。このコードは、doFooProc 定義の構文エラーを理由にコンパイルできません。
class bar =
object (self)
method doFooProc = (new Foo "test")#process
end;;
class foo (param1:string)=
object (self)
method process = Printf.printf "%s\n" "Processing!"
initializer Printf.printf "Initializing with param = %s\n" param1
end;;
さらに、「let」構文は、クラス定義内では使いにくいようです。何故ですか?
class bar =
object (self)
method doFooProc =
let xxx = (new Foo "test");
xxx#process
end;;
class foo (param1:string)=
object (self)
method process = Printf.printf "%s\n" "Processing!"
initializer Printf.printf "Initializing with param = %s\n" param1
end;;
doFooProc メソッドでクラス foo の新しいオブジェクトを作成し、インスタンス化された foo のプロセス コマンドを呼び出すにはどうすればよいですか?