나는 OCaml의에서이 정말 기본 클래스가 있습니다간단한 OCaml의 데이터 구조
class handler rule callback methods =
object(self)
method matches test_string test_method =
let r = Str.regexp rule in
match Str.string_match r test_string 0 with
| false -> false
| true -> methods = [] || List.exists (fun nth_method -> nth_method = test_method) methods
end
하지만 그것은 컴파일 할 수 없습니다 (파일이 handler.ml입니다) :
File "handler.ml", line 1, characters 6-339:
Error: Some type variables are unbound in this type:
class handler :
string ->
'a -> 'b list -> object method matches : string -> 'b -> bool end
The method matches has type string -> 'b -> bool where 'b is unbound
을
비교해 보면 꽤 이해할 수 있습니다. test_method
과 methods
의 요소가 같은 유형이 될 것으로 예상됩니다. 게다가, 타입 시스템은 분명히 타입이 모두 'b
이라는 것을 알기 때문에, 왜 그것이 문제가됩니까? (공식적으로, methods
문자열의 목록입니다.)
좋습니다. 고맙습니다! 이것은 매우 도움이되었습니다. – eatonphil