From: Julien Signoles <Julien.Signoles@lri.fr>
To: Christian Sternagel <christian.sternagel@uibk.ac.at>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Problem with Functors and Module Types
Date: Fri, 1 Aug 2008 13:58:52 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.63.0808011351440.28740@serveur9-10.lri.fr> (raw)
In-Reply-To: <4892EF0C.5090505@uibk.ac.at>
Hello,
> once again I have some problems using functors with module types. I produced
> following (almost?) minimal example:
>
> module type MT_M = sig
> type s
> type t = A of s | B of t list
> val f : t -> t
> end
>
> module type MT_N = sig
> module M : MT_M
> val f : 'a -> M.t
> end
>
> module type MT_A = sig
> type t
> end
>
> module MakeM (A : MT_A) : MT_M with type s = A.t = struct
> type s = A.t
> type t = A of s | B of t list
> let f x = x
> end
>
> module MakeN (A : MT_A) (* : MT_N *) = struct
> module M = MakeM (A)
> let f _ = M.B []
> end
>
> module A = struct
> type t = int
> end
>
> module M = MakeM (A)
> module N = MakeN (A)
>
> let _ = (M.f (N.f 1))
>
> This expression has type N.M.t = MakeN(A).M.t but is here used with type
> M.t = MakeM(A).t
There are two different solutions (at least).
===
1) Externalize the sum type and use the "with type" construct:
type 'a m = A of 'a | B of 'a m list
module type MT_M = sig type s type t = s m val f : t -> t end
...
module MakeM(A:MT_A):MT_M with type s = A.t = struct
type s = A.t
type t = s m
let f x = x
end
module MakeN(A:MT_A):MT_N with type M.s = A.t and type M.t = A.t m = struct
...
end
...
===
2) Use the "with module construct"
module MakeN(A:MT_A):MT_N with module M = MakeM(A) = struct
...
end
===
The second solution is more elegant.
Hope this helps,
Julien Signoles
prev parent reply other threads:[~2008-08-01 11:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-01 11:10 Christian Sternagel
2008-08-01 11:58 ` Julien Signoles [this message]
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=Pine.LNX.4.63.0808011351440.28740@serveur9-10.lri.fr \
--to=julien.signoles@lri.fr \
--cc=caml-list@yquem.inria.fr \
--cc=christian.sternagel@uibk.ac.at \
/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