Stupid question re:modules

Brian Hurt
 Jacques Garrigue
 Julien Moutinho
 Vincent Aravantinos
[
Home
]
[ Index:
by date

by threads
]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
Date:  20070824 (04:31) 
From:  Julien Moutinho <julien.moutinho@g...> 
Subject:  Re: [Camllist] Stupid question re:modules 
On Thu, Aug 23, 2007 at 08:32:22PM 0400, Brian Hurt wrote: > > I should just know this. So let's say I have two module types defined: > > module type Foo = sig > type 'a t > val foo : 'a > 'a t > end;; > > module type Bar = sig > type 'a t > val bar : 'a > 'a t > end;; > > Now, I want to define a module that is both a Foo and a Bar without cutting > and pasting the module definitions around. I've been trying to do: > > module Baz : sig > type 'a baz > include Foo with type 'a t = 'a baz > include Bar with type 'a t = 'a baz > end;; > > but this blows up on the Bar line (multiple definitions of 'a t). > > There is a solution to this, I'm just being stupid and forgetting what it > is. Hints would be appreciated. > > Brian I might haven't got exactly what you want, but, with control over Foo and Bar, and starting from the structure, I would have written : module type Foo = functor (T: T) > sig val foo : 'a > 'a T.t end module type Bar = functor (T: T) > sig val bar : 'a > 'a T.t end module Baz = functor (T: T) > functor (Foo: Foo) > functor (Bar: Bar) > struct include T type 'a baz = 'a t module Foo = Foo(T) module Bar = Bar(T) include Foo include Bar end Then I would have generated the signature automatically with i. But if you really want a short .mli without redundancy, I see no solution, even for the above functorized code. Because : 1/ unable to override or delete elements from a signature 2/ unable to get the signature of a structure from a functor in a signature. I mean, given this : module type T = sig end module type F = functor (T: T) > sig end This signature does not work : module B : functor (T: T) > functor (F: F) > sig module M : F(T) end nor this : module B : functor (T: T) > functor (M: F(T)) > sig end nor this : module B : functor (T: T) > functor (F: F) > sig include F(T) end nor this : module B : functor (T: T) > functor (F: F) > sig open F(T) end Despite the fact that the structured version of the first two signatures work. And that I do not understand why they all do not work, since it's a kind of substitution, isn't it? Anyway, hope you'll find a way to _avoid_ your problem.