From: Benoit deBoursetty <b-db@graphics.lcs.mit.edu>
To: Andrew Kay <akay@sharp.co.uk>
Cc: caml-list@inria.fr
Subject: Re: mutually recursive types and modules
Date: Wed, 12 May 1999 12:55:36 -0400 (EDT) [thread overview]
Message-ID: <Pine.SGI.3.93.990512121943.4863B-100000@tint.lcs.mit.edu> (raw)
In-Reply-To: <199905111632.RAA19705@byrd.sle.sharp.co.uk>
Hi,
I have a method that could help solve your problem. The thing is,
the new "functors" feature looks very problematic to we programmers...
I have slightly modified the set.ml file (normally in your ocaml
libraries directory) and saved it under another name, to accept
polymorphic types.
Basically the input type signature is no longer
# module type OrderedType =
sig
type t
val compare: t -> t -> int
end
but
# module type PolyOrderedType =
sig
type 'a t
val compare: 'a t -> 'a t -> int
end
as this had been previously suggested in this mailing-list (I can't
remember the name of that suggestion, but I'd like to thank him very much)
Then I would declare
# type 'a node =
{ node_id : int;
data : 'a
}
(which in fact you could replace by int * 'a)
The input module for my Make functor is then
# module OrderedNodes =
struct
type 'a t = 'a node
let compare n1 n2 = Pervasives.compare n1.node_id n2.node_id
end
and finally
module NodeSet = Make(OrderedNodes)
After that, you can put what you want in the 'a...
In your case, you would have to use recursive types :
# type mynode_data = { edge_list : mynode NodeSet.t ; ... }
and mynode = mynode_data node
Note that the "polymorphic sets" can do what the original O'CaML sets do :
the input module type doesn't have to be really variant. For instance, for
a set over the integers, you would just use
# module OrderedIntegers =
(struct
type 'a t = int
let compare = Pervasives.compare
end
: PolyOrderedType)
as an input signature.
You can also do what Caml-light did, which was implementing 'a sets,
systematically compared with Pervasives.compare. That is not available
with the original O'CaML Set.Make functor, but it works with this one.
Here's the corresponding PolyOrderedType that works for any element type,
with lexicographic ordering :
# module LexOrderedType =
struct
type 'a t = 'a
let compare = Pervasives.compare
end
So, that answers your question, I think. Yet it adds a level in your
typing (you have to go through the "data" field first).
Benoit de Boursetty
Ecole Polytechnique - X96
Permanent address :
Benoit.de-Boursetty@polytechnique.org)
Current address :
b-db@graphics.lcs.mit.edu
next prev parent reply other threads:[~1999-05-14 10:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-05-11 16:32 Andrew Kay
1999-05-12 16:55 ` Benoit deBoursetty [this message]
1999-05-12 18:04 ` Markus Mottl
1999-05-14 11:11 ` Francisco Valverde Albacete
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.SGI.3.93.990512121943.4863B-100000@tint.lcs.mit.edu \
--to=b-db@graphics.lcs.mit.edu \
--cc=akay@sharp.co.uk \
--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