Utknąłem z następującym problemem funktora w OCaml. Wklejam kod, abyś zrozumiał. ZasadniczoZrozumienie funktorów w OCaml
zdefiniowałem te dwa moduły w 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
i następujący funktor:
module Make(P: ProbPA): (M with type s = P.t) = struct
type s = P.t
(* implementation *)
end
Wtedy rzeczywiście korzystania z tych modułów I zdefiniowany nowy moduł bezpośrednio w pliku o nazwie 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 *)
Z trzeciego źródła (formulas.ml
) użyłem funktor z Prism
modułu:
module PrismPctl = Pctl.Make(Prism)
open PrismPctl
I wreszcie od main.ml
open Formulas.PrismPctl
(* code to prepare the object *)
PrismPctl.check_suite s.sys_state suite (* error here *)
i kompiluje daje następujący błąd
Error: This expression has type Prism.state = Prism.value array but an expression was expected of type Formulas.PrismPctl.s
Z tego, co mogę zrozumieć jakiś rodzaj złe aliasowanie nazw, są takie same (ponieważ value array
jest typem zdefiniowanym jako t
i użył M with type s = P.t
w funatorze), ale sprawdzanie typu nie uważa ich za takie same.
Naprawdę nie rozumiem, gdzie jest problem, czy ktoś może mi pomóc?
góry dzięki
nie wiem wystarczająco dużo o OCaml pomóc, ale jest to możliwe, że to poprzednie pytanie jest podobny problem? http://stackoverflow.com/questions/640510/functors-in-ocaml – Gian
@Gian: to ten sam problem, ale jeśli to zrozumiesz, jesteś już na najlepszej drodze do tego, aby nie zadawać pytania w pierwsze miejsce. – Gilles