OCaml: type incompatibilities between sets -
i'm having troubles type incompatibilities in ocaml.
first, have file setbuilder.ml define functor creates order sets, functor s creates sets, , functor sm creates module containing useful functions work sets:
module (m: sig type t end) = struct type t = m.t let compare = pervasives.compare end module s (p: sig type t end): set.s type elt = p.t = set.make (so (p)) module sm (m: sig type t end): sig type t = m.t module s: set.s type elt = t type set = s.t ... end = struct module s = s (m) ... end
(in such situation i'm used combining such 3 modules 1 recursive module, appears ocaml doesn't let create recursive modules when parameter excepted (i.e., when it's functor)).
then in different file, called module_u.ml, define module u function foo important:
module u (m: sig type t end): sig module s : set.s type elt = m.t type elt = m.t type eltset = s.t val foo: eltset -> eltset -> bool end = struct module s = s (m) let foo s1 s2 = ... end
and in main.ml, define module containing type i'll using,
module t : sig type t=int end = struct type t=int end
then instantiate module sm , obtain set s:
module sm = sm (t) module intset = sm.s
then instantiate module u , attempt use function foo:
module u = u (t) let bar (s1:intset.t) (s2:intset.t) : bool = u.foo s1 s2
but error message
file "main.ml", line 303, characters 38-39 (which corresponds s1, in u.foo s1 s2): error: expression has type intset.t = setbuilder.sm(t).s.t expression expected of type u.eltset = module_u.u(t).s.t
what don't understand, why problem, since both u , sm modules created same module t, meaning type of 2 sets created should same.
if can provide thoughts on i'll thankful.
try using module s : module type of s(m)
, or alternatively module s : set.s type elt = m.t , type t = s(m).t
. problem module s : set.s type elt = m.t
doesn't constrain type s.t
Comments
Post a Comment