From: Leo White <lpw25@cam.ac.uk>
To: "Jocelyn Sérot" <Jocelyn.SEROT@univ-bpclermont.fr>
Cc: OCaML Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Question on functors (again...)
Date: Mon, 20 Jan 2014 20:57:26 +0000 [thread overview]
Message-ID: <87ppnm5q2x.fsf@study.localdomain> (raw)
In-Reply-To: <C05B2D5D-522F-4EFB-BF7B-E705780FA98F@univ-bpclermont.fr> ("Jocelyn \=\?utf-8\?Q\?S\=C3\=A9rot\=22's\?\= message of "Mon, 20 Jan 2014 17:34:21 +0100")
Jocelyn Sérot <Jocelyn.SEROT@univ-bpclermont.fr> writes:
> I was expecting that the constraints in the definition of the Make functor (".. with type elt=E.t and module Elt =E")
> would automatically enforce the type equality "elt = Elt.t" for all modules defined by applying Make (such as S1 and
> S2). This is obviously not the case. I just can't see how to enforce this..
The compiler doesn't know that your `S1` and `S2` arguments have been
made with the `Make` functor so it cannot assume those constraints. You
should add the constraints to the `SET` module type itself:
module type SET = sig
type t
type elt
module Elt : sig type t = elt end
val choose : t -> elt
val singleton : elt -> t
end
You've simplified your example, so there may be important complexity
that you've left out, but your code seems to be unnecessarily
complicated. You can probably simplify it to something that looks more
like the code below.
Regards,
Leo
module type ELT = sig type t end
module type SET = sig
type t
type elt
val choose: t -> elt
val singleton: elt -> t
end
module Make (E : ELT) : SET with type elt = E.t = struct
type elt = E.t
type t = elt list
module Elt = E
let choose s = List.hd s
let singleton e = [e]
end
module MakePair (E1: ELT) (E2: ELT) : sig
include ELT with type t = E1.t * E2.t
val product : E1.t -> E2.t -> t
end = struct
type t = E1.t * E2.t
let product x y = x,y
end
module MakeProduct (S1: SET) (S2: SET) : sig
include SET with type elt = S1.elt * S2.elt
val product : S1.t -> S2.t -> t
end = struct
module P = MakePair(struct type t = S1.elt end)(struct type t = S2.elt end)
module S = Make(P)
include S
let product s1 s2 = S.singleton (P.product (S1.choose s1) (S2.choose s2))
end
next prev parent reply other threads:[~2014-01-20 20:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-20 16:34 Jocelyn Sérot
2014-01-20 20:57 ` Leo White [this message]
2014-01-21 11:09 ` SEROT Jocelyn
2014-01-21 11:30 ` Josh Berdine
2014-01-21 14:30 ` SEROT Jocelyn
2014-01-21 13:32 ` Leo White
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=87ppnm5q2x.fsf@study.localdomain \
--to=lpw25@cam.ac.uk \
--cc=Jocelyn.SEROT@univ-bpclermont.fr \
--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