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 PAA23376; Wed, 23 May 2001 15:57:39 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA23405 for ; Wed, 23 May 2001 15:57:38 +0200 (MET DST) Received: from serveur3-1.labri.u-bordeaux.fr (serveur3-1.labri.u-bordeaux.fr [147.210.8.180]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f4NDvcf21192 for ; Wed, 23 May 2001 15:57:38 +0200 (MET DST) Received: (from vanicat@localhost) by serveur3-1.labri.u-bordeaux.fr (8.11.0/8.11.0) id f4NDvtF28744; Wed, 23 May 2001 15:57:55 +0200 X-Authentication-Warning: serveur3-1.labri.u-bordeaux.fr: vanicat set sender to vanicat@labri.u-bordeaux.fr using -f To: caml-list@inria.fr Subject: Re: [Caml-list] weak type variables in module type declarations References: <200105231324.f4NDOgc28482@mail.iis.sinica.edu.tw> From: Remi VANICAT In-Reply-To: <200105231324.f4NDOgc28482@mail.iis.sinica.edu.tw> Date: 23 May 2001 15:57:55 +0200 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Tyng-Ruey Chuang writes: > Dear all, > > O'caml compiler does not seem to recognize user-specified > weak type variables. The compiler, however, will automatically > produce weak type variables when they are needed. > This behavior has been observed and reported as "Id 246" > in the "Known bugs" list (and classified as "not a bug"). See > http://www.ocaml.org/bin/caml-bugs/not%20a%20bug?expression=weak;user=guest > > What do you do to get around this? In my case, the week type variables > are indeed useful, and I want to keep them. But since I have no way > in putting weak type variables in module type declarations, I am prevented > to program in a modular way. Consider the following code segment: > > > let ($) f g x = f (g x) (* functional composition *) > let id x = x (* the identity function *) > > module Sum = > struct > type ('a, 'b) t = Pink of 'a | Blue of 'b > let pair = (id $ (fun a -> Pink a), id $ (fun b -> Pink b)) > end i really don't believe you want weak type here : weak type are that will be determine latter : if you make a Sum.pair 1 2 then after this, Sum.pair will have the mostly monomorphic type val pair : (int -> (int, '_b) t) * (int -> (int, '_d) t) you may have something very similar, but without weaktype, thanks to an eta-transformation : module Sum = struct type ('a, 'b) t = Pink of 'a | Blue of 'b let pair = ((fun x -> (id $ (fun a -> Pink a)) x),(fun x -> (id $ (fun b -> Pink b)) x));; end which have as type: module Sum : sig type ('a, 'b) t = Pink of 'a | Blue of 'b val pair : ('a -> ('a, 'b) t) * ('c -> ('c, 'd) t) end Which is probably what you want. The problem with weak type is mostly a FAQ, you should read the FAQ at this subject -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr