From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA18320; Wed, 25 Apr 2001 18:20:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA18150 for ; Wed, 25 Apr 2001 18:20:31 +0200 (MET DST) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f3PGKTP16925; Wed, 25 Apr 2001 18:20:29 +0200 (MET DST) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id f3PGKSq81973 ; Wed, 25 Apr 2001 18:20:28 +0200 (CEST) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id SAA26669 ; Wed, 25 Apr 2001 18:20:28 +0200 (MET DST) Date: Wed, 25 Apr 2001 18:20:27 +0200 (MET DST) From: Alain Frisch To: Francois Thomasset cc: caml-list@inria.fr Subject: Re: [Caml-list] le neophyte et les modules, types parametres In-Reply-To: <200104251549.f3PFn0116328@ionie.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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