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 OAA22160 for caml-redistribution; Thu, 5 Feb 1998 14:18:22 +0100 (MET) 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 UAA04620 for ; Wed, 4 Feb 1998 20:08:26 +0100 (MET) Received: from macon.informatik.uni-tuebingen.de (macon2.Informatik.Uni-Tuebingen.De [134.2.13.2]) by nez-perce.inria.fr (8.8.7/8.8.5) with ESMTP id UAA12666 for ; Wed, 4 Feb 1998 20:08:20 +0100 (MET) Received: from marvin.informatik.uni-tuebingen.de (marvin.Informatik.Uni-Tuebingen.De [134.2.12.11]) by macon.informatik.uni-tuebingen.de (8.8.4/8.8.3/AIX-4.1/WSI-1.0) with SMTP id UAA61380; Wed, 4 Feb 1998 20:08:19 +0100 Received: from localhost by marvin.informatik.uni-tuebingen.de (AIX 4.1/UCB 5.64/4.03) id AA20200; Wed, 4 Feb 1998 20:07:52 +0100 Date: Wed, 4 Feb 1998 20:07:51 +0100 (MET) From: Simon Helsen X-Sender: helsen@marvin To: Pierre CASTERAN Cc: caml-list@inria.fr Subject: Re: Weak types ? In-Reply-To: <199802031546.QAA21882@scrasmeustache.labri.u-bordeaux.fr> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis > I suppose the following problem concerns "weak" types, but i don't see > the reason (I have no assignment at all in this definitions !) > > let toto = > let id x = x > in id id;; > (* > val toto : '_a -> '_a = > ^ ^ > > why not " 'a " ? > > *) the problem is due to the polymorphic application (id id). Caml uses something which is called "value polymorphism", a restriction which is also adopted in SML'97, although Caml still allows you to use this pseudo-polymorphic function (i.e. it allows you to instantiate the poly-variable once and then fixing it). It has absolutely nothing to do with the use of assignments or anything alike. As far as I know, a variable (e.g. toto) can only be given a (true) polymorphic type scheme if the exp (e.g. id id) is "non-expansive" (Standard ML terminology). However, every application *is* expansive. This is just a syntactic restriction which definitely avoids the known problems with polymorphic references, but is indeed sometimes a bit to restrictive, although it appears to be rarely a problem in practice. This scheme is now also adopted in SML because other more semantic based approaches (like tracing references etc.) turned out to be ugly and could mess up the signatures of modules. > toto 5;; > (* ok *) > > toto (fun z -> z);; > > (* > This expression has type 'a -> 'a but is here used with type int > *) Exactly. The pseudo-poly var. has been already instantiated with an integer and is now fixed to that, meaning it can't be used otherwise. This exactly avoids the type-problems in case of references. Note that in SML your definition of toto would be refused in the first place. cheers, Simon ----------------------- Simon Helsen ------------------------ -- Wilhelm-Schickard-Institut fuer Informatik -- -- Arbeitsbereich Programmierung (PU) -- -- Universitaet Tuebingen, Germany -- ------------------------------------------------------------- -- http://www-pu.informatik.uni-tuebingen.de/users/helsen/ --