OCaml에서 다음과 같은 펑터 문제가 있습니다. 내가 이해할 수 있도록 일부 코드를 붙여 넣습니다. 기본적으로 OCaml의 펑터 이해하기
나는pctl.ml
이 두 모듈을 정의 :
module type ProbPA = sig
include Hashtbl.HashedType
val next: t -> (t * float) list
val print: t -> float -> unit
end
module type M = sig
type s
val set_error: float -> unit
val check: s -> formula -> bool
val check_path: s -> path_formula -> float
val check_suite: s -> suite -> unit
end
다음과 같은 펑터 :
다음module Make(P: ProbPA): (M with type s = P.t) = struct
type s = P.t
(* implementation *)
end
실제로 내가 prism.ml
라는 파일에 직접 새 모듈을 정의 된이 모듈을 사용하기를 :
type state = value array
type t = state
type value =
| VBOOL of bool
| VINT of int
| VFLOAT of float
| VUNSET
(* all the functions required *)
세 번째 소스가) 내가 Prism
모듈로 펑터를 사용 :
module PrismPctl = Pctl.Make(Prism)
open PrismPctl
그리고 마지막으로 main.ml
에서
open Formulas.PrismPctl
(* code to prepare the object *)
PrismPctl.check_suite s.sys_state suite (* error here *)
및 컴파일 다음과 같은 오류 나는 일종의가 이해할 수있는 일부터
Error: This expression has type Prism.state = Prism.value array but an expression was expected of type Formulas.PrismPctl.s
에게 제공 이름의 잘못된 앨리어싱은 동일합니다 (value array
은 t
으로 정의 된 유형이므로 '는 펑터에서 M with type s = P.t
을 사용했습니다.)하지만 형식 검사기는 그것들을 동일하게 간주하지 않습니다.
나는 정말로 어디에 문제가 있는지 이해하지 못해 누구도 나를 도울 수 있습니까? 사전
에
Make
의 서명에with type s = P.t
을 포함 가정 내가 OCaml의 도와 대해 충분히 모르겠지만, 가능하다이 이전 질문은 비슷한 문제인가? http://stackoverflow.com/questions/640510/functors-in-ocaml – Gian@Gian : 그것은 근본적인 문제는 같지만, 이해한다면, 당신은 이미 당신의 질문에 질문 할 필요가 없습니다. 처음. – Gilles