From: Alain Frisch <frisch@clipper.ens.fr>
To: Francois Thomasset <Francois.Thomasset@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] le neophyte et les modules, types parametres
Date: Wed, 25 Apr 2001 18:20:27 +0200 (MET DST) [thread overview]
Message-ID: <Pine.GSO.4.04.10104251801510.4272-100000@clipper.ens.fr> (raw)
In-Reply-To: <200104251549.f3PFn0116328@ionie.inria.fr>
On Wed, 25 Apr 2001, Francois Thomasset wrote:
> Question: how to use a parameter type in a module, cf example above
The same problem has already been discussed on this list (or maybe on
comp.lang.{ml,functional}, not sure), and I think there is no good
solution for the moment.
This issue struck me again just two hours ago. I wanted to build sets
or hash tables over "stamped" values (using the stamp for
comparison/hashing), so I defined a module whose signature is:
module Stamp :
sig
type 'a t = { stamp : int; data : 'a }
val build : 'a -> 'a t
val data : 'a t -> 'a
val compare : 'a t -> 'a t -> int
val hash : 'a t -> int
val equal : 'a t -> 'a t -> bool
end
(I don't want Stamp itself to be a functor, because of the lack of
recursivity between modules).
But then (Set.Make(Stamp)) doesn't work. There would be no problem
to have a generic implementation of Set on parametrized ordered types.
But then you may want to use it with types parametrized with two type
variables, etc ... The solution is presently to copy the
implementation from stdlib/set.ml. The *only* modification is to replace
in the implementation:
type t = Empty | Node of t * elt * t * int
with
type 'a t = Empty | Node of 'a t * 'a elt * 'a t * int
or
type ('a,'b) t = Empty | Node of ('a,'b) t ...
and so on.
The specification must me changed accordingly. It seems that the
transformation is completely automatic and syntactic.
Would there be any problem to accept in functor applications modules whose
types have extra parameters, reflecting adequate modification on the
result ? (this is only a typing problem; as far as I understand it,
there is absolutely no problem for runtime; adding type parameters
implies no new coercion of runtime representations)
--
Alain Frisch
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
prev parent reply other threads:[~2001-04-25 16:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-25 15:49 Francois Thomasset
2001-04-25 16:16 ` Brian Rogoff
2001-04-25 16:20 ` Alain Frisch [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.GSO.4.04.10104251801510.4272-100000@clipper.ens.fr \
--to=frisch@clipper.ens.fr \
--cc=Francois.Thomasset@inria.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