caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Julien Moutinho <julien.moutinho@gmail.com>
To: Brian Hurt <bhurt@spnz.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Stupid question re:modules
Date: Fri, 24 Aug 2007 06:31:03 +0200	[thread overview]
Message-ID: <20070824043102.GA3299@jiyu.gnu> (raw)
In-Reply-To: <Pine.LNX.4.64.0708232023160.12703@localhost>

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.


  parent reply	other threads:[~2007-08-24  4:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-24  0:32 Brian Hurt
2007-08-24  2:56 ` [Caml-list] " Jacques Garrigue
2007-08-24  4:31 ` Julien Moutinho [this message]
2007-08-24 10:16 ` Vincent Aravantinos
2007-09-23  9:37   ` David Teller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070824043102.GA3299@jiyu.gnu \
    --to=julien.moutinho@gmail.com \
    --cc=bhurt@spnz.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).