Browse thread
Strategy to avoid name collision in signatures
[
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: | -- (:) |
| From: | Julien Moutinho <julien.moutinho@g...> |
| Subject: | Re: [Caml-list] Strategy to avoid name collision in signatures |
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.