From: Scott Duckworth <scott.duckworth@gmail.com>
To: caml-list <caml-list@inria.fr>
Subject: type troubles with functors
Date: Wed, 22 Jun 2005 00:53:52 -0400 [thread overview]
Message-ID: <8ecdad970506212153417f77b5@mail.gmail.com> (raw)
I'm having trouble figuring out a way to represent functor modules as
types in a module type definition. For lack of a better way of
explaining it, here's the problem I'm having in code:
*************************************
(* OrderedSet.mli *)
(* Ordered sets over ordered types *)
module type OrderedType = (* same as in .ml file *)
module type S = (* same as in .ml file *)
module Make (Ord : OrderedType) : S with type elt = Ord.t
*************************************
(* OrderedSet.ml *)
(* Ordered sets over ordered types *)
module type OrderedType = sig
type t
val compare : t -> t -> int
end
module type S = sig
type elt
type t
val to_list : t -> elt list
val to_set : t -> EltSet.t (* PROBLEM *)
(* ... *)
end
module Make (Ord : OrderedType) = struct
module EltSet = Set.Make(Ord) (* THIS IS WHAT I WANT TO RETURN *)
type elt = Ord.t
type t = { l : elt list; s : EltSet.t }
let to_list s = s.l
let to_set s = s.s (* THIS IS WHERE I WANT TO RETURN A SET *)
(* ... *)
end
*************************************
I realize that EltSet.t is not defined at the two points I have noted
a problem, I'm simply stating my intention. The problem is that
OrderdSet.S does not know the OrderedSet.OrderedType that will be used
in OrderedSet.Make, but it does know that it will be of type Set.S.t.
(This is one instance where I wish Set was implemented as a
parameterized type, not a functor.)
My question is, how can I correctly type to_set? I have tried many
different configurations of Set.Make and Set.S, but none of them have
worked. If anyone knows how this can be done in OCaml's type system,
please let me know. Thanks!
--
Scott Duckworth
next reply other threads:[~2005-06-22 4:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-22 4:53 Scott Duckworth [this message]
2005-06-22 6:48 ` [Caml-list] " Pietro Abate
2005-06-22 7:50 ` Virgile Prevosto
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=8ecdad970506212153417f77b5@mail.gmail.com \
--to=scott.duckworth@gmail.com \
--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