OCaml의 OOP 구조체에 대해 배우고 있으며, 객체 외부에서 type 키워드를 사용하지 않고 polymorphic match 문을 표현하는 방법을 모를 때까지 부분적으로 이것을 구현했습니다.OCaml의 OOP 구조체에서 타입을 결정하기
class bar (param:string) =
object (code)
end;;
class foo param =
object (code)
initializer
match param with
string -> Printf.printf "param is a string"
| bar -> Printf.printf "param is a bar"
end;;
let b = new bar "a string";;
let f1 = new foo "test";;
let f2 = new foo b;;
즉석에서 전달되는 객체의 유형을 결정할 수 있습니까?