On Tue, 27 Mar 2007, [UTF-8] Rónán Daly wrote:
> It seems to be a multiple inheritance type problem, but
there if no real
> conflict here, as the type t is exactly the same in
both included module
> signatures.
>
> Can anyone see a way around this problem?
Well, the probsem here is that include is essentially a
simple textual
inclusion, so that you are in effect typing
module type CD = sig
type t
val f : t -> ...
val g : t -> ...
val h : t -> ...
val i : t -> ...
type t
val f : t -> ...
val g : t -> ...
val l : t -> ...
val m : t -> ...
end
Hence the multiple definition error.
A possibly better thing to do here would be the use of
functors. Here's
an overly verbose example that I'm sure isn't as good as it
could be (I
really need to re-read some of Norman Ramsey's work on
modules):
module type B =
sig
type t = X | Y
val f : t -> int
val g : t -> char
end
;;
module BMod : B =
struct
type t = X | Y
let f = function X -> 1 | Y -> 2
let g = function X -> 'x' | Y -> 'y'
end
;;
module type C =
functor (BMod : B) ->
sig
type t = BMod.t
val h : t -> string
end
;;
module CMod =
functor (BMod : B) ->
struct
open BMod
type t = BMod.t
let h = function X -> "x" | Y ->
"y"
end
;;
module type D =
functor (BMod : B) ->
sig
type t = BMod.t
val j : t -> float
end
;;
module DMod =
functor (BMod : B) ->
struct
open BMod
type t = BMod.t
let j = function X -> 1. | Y -> 2.
end
;;
module type CD =
functor (BMod : B) ->
functor (CMod : C) ->
functor (DMod : D) ->
sig
type t = BMod.t
val l : t -> int * float
val m : t -> char * string
end
;;
module CDMod =
functor (BMod : B) ->
functor (CMod : C) ->
functor (DMod : D) ->
struct
open BMod
module CM = CMod(BMod)
module DM = DMod(BMod)
type t = BMod.t
let l t = BMod.f t,DM.j t
let m t = BMod.g t,CM.h t
end
;;
module CDM = CDMod (BMod) (CMod) (DMod);;
William D. Neumann
---
"There's just so many extra children, we could just
feed the
children to these tigers. We don't need them, we're not
doing
anything with them.
Tigers are noble and sleek; children are loud and
messy."
-- Neko Case
Life is unfair. Kill yourself or get over it.
-- Black Box Recorder
[Non-text portions of this message have been removed]
Archives up to November 11, 2006 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
ht
tp://groups.yahoo.com/group/ocaml_beginners/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:ocaml_beginners-digest@yahoogroups.com
mailto:ocaml_beginners-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|