From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: bhurt@spnz.org
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Stupid question re:modules
Date: Fri, 24 Aug 2007 11:56:08 +0900 (JST) [thread overview]
Message-ID: <20070824.115608.24601967.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <Pine.LNX.4.64.0708232023160.12703@localhost>
From: Brian Hurt <bhurt@spnz.org>
> 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.
Unfortunately, there is no solution to this, as you cannot remove a
declaration from a signature, and include cannot overwrite existing
type definitions. There was a paper in ICFP'2005 on how to solve this,
but I'm not aware of any plan to follow it.
If you're ready to write longer signatures, there is a workaround.
module type T = sig type 'a t end
module FooS(X:T) = struct
module type S = sig
val foo : 'a -> 'a X.t
end
end
module BarS(X:T) = struct
module type S = sig
val bar : 'a -> 'a X.t
end
end
module Baz : sig
module T : sig type 'a t end
include FooS(T)
include BarS(T)
end
The basic idea if you want to be able to construct signatures
modularly is to always keep types and function declarations
separated.
Jacques Garrigue
next prev parent reply other threads:[~2007-08-24 2:56 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 ` Jacques Garrigue [this message]
2007-08-24 4:31 ` [Caml-list] " Julien Moutinho
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=20070824.115608.24601967.garrigue@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--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