From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA28772 for caml-redistribution; Tue, 16 Feb 1999 08:12:31 +0100 (MET) 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 SAA10194 for ; Mon, 15 Feb 1999 18:45:32 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id SAA03152; Mon, 15 Feb 1999 18:45:31 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA19162; Mon, 15 Feb 1999 18:45:30 +0100 (MET) From: Pierre Weis Message-Id: <199902151745.SAA19162@pauillac.inria.fr> Subject: Re: Non generalizable type of constants? To: ohl@hep.tu-darmstadt.de Date: Mon, 15 Feb 1999 18:45:30 +0100 (MET) Cc: caml-list@inria.fr In-Reply-To: <199902151659.RAA10464@heplix4.ikp.physik.tu-darmstadt.de> from "Thorsten Ohl" at Feb 15, 99 05:59:41 pm X-Mailer: ELM [version 2.4 PL24 ME8] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: weis > OK, maybe I'm really too dumb to use O'Caml, but can some kind soul > explain why in > > module type Ring = sig type t val unit : t end > > module Group (R : Ring) = > struct > type 'a t = Unit | Prod of (R.t * 'a) > let unit = Unit > let atom a = Prod (R.unit, a) > end > > module FreeRing (R : Ring) = > struct > module M = Group(R) > module A = Group(R) > type 'a t = 'a M.t A.t > let unit_good = A.Prod (R.unit, M.unit) > let unit_bad = A.atom (M.unit) > end > > O'Caml infers the types > > val unit_good : 'a M.t A.t > val unit_bad : '_a M.t A.t Because unit_bad is a function application (that cannot be generalized, due to value restriction polymorphism), while unit_good is a constructor application and hence is a generalizable value. > respectively? As one might guess, I want to make [['a Group.t]] > abstract (because I want to hide a more complicated structure), in > which case the definition of [[unit_good]] will not work any more. At > the same time, I need [[unit]] to have type [['a FreeRing.t]] and not > [['_a FreeRing.t]]. > > The usual tricks for functions with non generalizable argument types > don't work. What can one do for constants? Or am I overlooking > something obvious? If you insist at abstracting the type Groupe.t, I'm not aware of any solution to your problem, except turning your unit_bad identifier into a function let unit_bad () = A.atom (M.unit). More generally, what you call constants are computed values, even if the computation is simple in your case, hence we have the general problem of references. > Merci, > -Thorsten > -- > Thorsten Ohl, Physics Department, TU Darmstadt -- ohl@hep.tu-darmstadt.de > http://heplix.ikp.physik.tu-darmstadt.de/~ohl/ [<=== PGP public key here] > Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/