From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA27107 for caml-redistribution; Fri, 3 Dec 1999 14:55:50 +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 OAA16040 for ; Fri, 3 Dec 1999 14:51:25 +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 OAA14968; Fri, 3 Dec 1999 14:50:56 +0100 (MET) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA04967; Fri, 3 Dec 1999 14:50:47 +0100 (MET) From: Pierre Weis Message-Id: <199912031350.OAA04967@pauillac.inria.fr> Subject: Re: Why is this not allowed? To: prevost@maya.com (John Prevost) Date: Fri, 3 Dec 1999 14:50:47 +0100 (MET) Cc: caml-list@inria.fr In-Reply-To: <87n1rtb2z7.fsf@isil.maya.com> from "John Prevost" at Dec 2, 99 01:40:44 pm X-Mailer: ELM [version 2.4 PL24 ME8] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis > Damien Doligez writes: > > > ># let rec id'' = id;; > > >This kind of expression is not allowed as right-hand side of `let rec' > > > > Because we don't know how to compile "let rec x = x" or > > let rec x = y > > and y = x > > > > Moreover, you can just remove the "rec" and it works. It is possible > > to implement "let rec var1 = var2", but the usefulness is quite small > > compared to the amount of code we would need to write. > > Well, you can't quite. Because of the value restriction, id'' defined > like this: > > let id'' = id;; > > has type: > > id'' : '_a -> '_a > > (That is, it'll only work for a single type.) > > John. There is some confusion here: since «id» is an expression that is a mere variable, it is not expansive; hence it can be safely generalized; hence it can be used with different uncompatible types: # let id x = x;; val id : 'a -> 'a = # let id'' = id;; val id'' : 'a -> 'a = # id'' 1, id'' true;; - : int * bool = 1, true Rule of thumb concerning the polymorphism generalisation restriction: the restriction is performed by matching the right hand side expression e of a let definition: 1 if e is a constant, a variable expression, a function (that is a syntactically explicit function, introduced by the keyword fun or function), or a constructor application, then its type can safely be generalised. 2 otherwise the type of e is not generalized. Condition 1 is a rough approximation of the property ``the execution of e cannot create a polymorphic mutable value''; in practice, condition 2 means that if e is a function application then its type is not generalized. Best regards, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/