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 PAA22592; Wed, 23 May 2001 15:25:06 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 PAA22590 for ; Wed, 23 May 2001 15:25:05 +0200 (MET DST) Received: from mail.iis.sinica.edu.tw (mail.iis.sinica.edu.tw [140.109.20.50]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f4NDP3f20029 for ; Wed, 23 May 2001 15:25:04 +0200 (MET DST) Received: (from trc@localhost) by mail.iis.sinica.edu.tw (8.10.2/8.10.2) id f4NDOgc28482; Wed, 23 May 2001 21:24:42 +0800 (CST) Date: Wed, 23 May 2001 21:24:42 +0800 (CST) From: Tyng-Ruey Chuang Message-Id: <200105231324.f4NDOgc28482@mail.iis.sinica.edu.tw> To: caml-list@inria.fr Subject: [Caml-list] weak type variables in module type declarations Cc: trc@iiserv.iis.sinica.edu.tw Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 module type SUM = sig type ('a, 'b) t = Pink of 'a | Blue of 'b val pair : ('_a -> ('_a, '_b) t) * ('_a -> ('_a, '_b) t) end The compiler report module type SUM as module type SUM = sig type ('a, 'b) t = | Pink of 'a | Blue of 'b val pair : ('a -> ('a, 'b) t) * ('a -> ('a, 'b) t) end which is different from my specification. Therefore, I cannot write code like module Empty = functor (S: SUM) -> struct end module E = Empty(Sum) because the last line produces a "signature dismatch" error from the compiler. Of course, the dismatch goes away if the code for module Sum is changed to module Sum = struct type ('a, 'b) t = Pink of 'a | Blue of 'b let pair = ((fun a -> Pink a), (fun b -> Pink b)) end because the week type variables now disappear. However, this is not what I want. I program mostly in equational style. The function "id" in the original definition of module Sum in fact is a complex function that better to be left alone. I also need the two occurrences of the weak type variable '_a to resolve to the same type. The usual Obj.magic trick to coerce the compiler to accept unsafe value definition does not work either, as it cannot eliminate weak types. I will appreciate any thought on how to deal with this situation. Last, but not least, many thanks to the Caml team for the fine language and compiler. Tyng-Ruey Chuang ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr