From: Julien Moutinho <julien.moutinho@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Strategy to avoid name collision in signatures
Date: Sun, 4 Nov 2007 01:01:17 +0100 [thread overview]
Message-ID: <20071104000116.GA2256@localhost> (raw)
In-Reply-To: <86tzo3nf8f.fsf@Llea.celt.neu>
On Sat, Nov 03, 2007 at 11:20:16PM +0100, Michaël Le Barbier wrote:
> In some piece of code, I use functors combined with include as a kind
> of macro facility. In this scheme, it can happen that an identifier is
> exported multiple times from various include directives, this ``name
> collision'' is an error, and I am looking for ways to avoid it
> whithout much annoyance. (OK, this is very vague, details and example
> are coming.)
[...]
I'm not sure if it could be of some help, but here is another scheme
wherein the functor <name>Type.Make does not include its argument PROTO,
so that there is no namespace conflict with type t.
However the PROTO structure can no longer be used anonymously:
include OrderedType.Make(struct type t let compare : t -> t -> int = Pervasives.compare end)
Gives the error message:
This functor has type
functor (PROTO : OrderedType.PROTO) ->
sig val ge : PROTO.t -> PROTO.t -> bool end
The parameter cannot be eliminated in the result type.
Please bind the argument to a module identifier
The module identifier <name>Type_PROTO should be ok.
module OrderedType =
struct
module type PROTO =
sig type t val compare : t -> t -> int end
module Make
(PROTO: PROTO) =
struct let ge t t' = PROTO.compare t t' >= 0 end
end
module FunnyType =
struct
module type PROTO =
sig type t val compare : t -> t -> int end
module Make
(PROTO: PROTO) =
struct let funny_ge t t' = PROTO.compare t t' >= 0 end
end
module OrderedType_PROTO =
struct type t let compare : t -> t -> int = Pervasives.compare end
module FunnyType_PROTO =
struct type t let compare : t -> t -> int = Pervasives.compare end
include OrderedType.Make(OrderedType_PROTO)
include FunnyType.Make(FunnyType_PROTO)
Which gives:
module OrderedType :
sig
module type PROTO = sig type t val compare : t -> t -> int end
module Make :
functor (PROTO: PROTO) ->
sig val ge : PROTO.t -> PROTO.t -> bool end
end
module FunnyType :
sig
module type PROTO = sig type t val compare : t -> t -> int end
module Make :
functor (PROTO: PROTO) ->
sig val funny_ge : PROTO.t -> PROTO.t -> bool end
end
module OrderedType_PROTO : sig type t val compare : t -> t -> int end
module FunnyType_PROTO : sig type t val compare : t -> t -> int end
val ge : OrderedType_PROTO.t -> OrderedType_PROTO.t -> bool
val funny_ge : FunnyType_PROTO.t -> FunnyType_PROTO.t -> bool
HTH,
Julien.
next prev parent reply other threads:[~2007-11-04 0:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-03 22:20 Michaël Le Barbier
2007-11-03 22:47 ` [Caml-list] " Andrej Bauer
2007-11-04 6:15 ` Michaël Le Barbier
2007-11-04 0:01 ` Julien Moutinho [this message]
2007-11-04 7:34 ` Michaël Le Barbier
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=20071104000116.GA2256@localhost \
--to=julien.moutinho@gmail.com \
--cc=caml-list@yquem.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