Ich bin ziemlich fest mit dem folgenden Funktor Problem in OCaml. Ich füge einen Teil des Codes ein, damit Sie es verstehen. GrundsätzlichFunktoren in OCaml verstehen
I definiert diese beiden Module in 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
und die folgende Funktors:
module Make(P: ProbPA): (M with type s = P.t) = struct
type s = P.t
(* implementation *)
end
Dann tatsächlich diese Module verwenden I definiert ein neues Modul direkt in einer Datei prism.ml
genannt:
type state = value array
type t = state
type value =
| VBOOL of bool
| VINT of int
| VFLOAT of float
| VUNSET
(* all the functions required *)
Von einer dritten Quelle (formulas.ml
) Ich habe den Funktors mit Prism
Modul verwendet:
module PrismPctl = Pctl.Make(Prism)
open PrismPctl
Und schließlich von main.ml
open Formulas.PrismPctl
(* code to prepare the object *)
PrismPctl.check_suite s.sys_state suite (* error here *)
und kompiliert gibt dem folgenden Fehler
Error: This expression has type Prism.state = Prism.value array but an expression was expected of type Formulas.PrismPctl.s
Von dem, was ich dort verstehen kann, eine Art schlechtes Aliasing der Namen, sie sind die gleichen (seit value array
ist der Typ definiert als t
und es 's verwendet M with type s = P.t
im Funktor), aber der Typ Checker betrachtet sie nicht als gleich.
Ich verstehe wirklich nicht, wo das Problem ist, kann mir jemand helfen?
Vielen Dank im Voraus
Ich weiß nicht genug über OCaml, zu helfen, aber es ist möglich, dass diese vorherige Frage ist ein ähnliches Problem? http://StackOverflow.com/Questions/640510/Functors-in-Coaml – Gian
@Gian: Es ist das gleiche Problem root, aber wenn Sie das verstehen, sind Sie bereits auf dem besten Weg, um die Frage in der nicht zu stellen erster Platz. – Gilles