Stephen Diehl has started a series of blog posts about module systems using OCaml as an example. This provides a nice introduction to the finer points.
I believe the last example in the blog aims to demonstrate that generative functors create new (incompatible) types.
a generative functor which is denoted by an extra parameter
()
which will produce an output module containing non-equal abstract types
But this is not the case here. Maybe I’m misunderstanding the point of the example.
module FA = F(A);;
module type S = sig type t val s : t end
module A : S
module F : functor (M : S) -> sig type a = M.t val b : a end
module FA : sig type a = A.t val b : a end
module GA = G(A)();;
module G : functor (M : S) () -> sig type a = M.t val b : a end
module GA : sig type a = FA.a val b : a end
utop # FA.b = GA.b;;
- : bool = true
G.a
isn’t abstract.
a generative functor which is denoted by an extra parameter () which will produce an output module containing non-equal abstract types
means “if the functor produces an abstract type t
, separate applications will make the resulting t
s not equal”
Yes. So the example given in the article doesn’t demonstrate what it talks about. Which is a bit unexpected.
It is not a matter of abstract types or not but a question of definitions
module F() = struct
type t = A | B
end
module M = F()
module N = F()
let error = [M.A;N.A]
compared to abbreviations
type original = A | B | C
module F () = struct
type t = original = A | B | C
end
module M = F()
module N = F()
let ok = [M.A; N.A]