From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 68511BB9A for ; Tue, 15 Nov 2005 14:12:04 +0100 (CET) Received: from ash25e.internode.on.net (ash25e.internode.on.net [203.16.214.182]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAFDC2nh032581 for ; Tue, 15 Nov 2005 14:12:03 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by ash25e.internode.on.net (8.12.9/8.12.6) with ESMTP id jAFDBtcT085506; Tue, 15 Nov 2005 23:41:56 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] function specialization From: skaller To: Vsevolod Fedorov Cc: caml-list@yquem.inria.fr In-Reply-To: <00a701c5e9da$1b0ebc20$670aa8c0@seva> References: <00a701c5e9da$1b0ebc20$670aa8c0@seva> Content-Type: text/plain Date: Wed, 16 Nov 2005 00:11:55 +1100 Message-Id: <1132060315.9002.24.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 4379DEA2.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 implicitly:01 ocaml:01 bug:01 quantifier:01 bug:01 wrote:01 sourceforge:01 polymorphic:01 simpler:01 expression:01 monomorphic:01 int:01 int:01 string:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Tue, 2005-11-15 at 14:45 +0300, Vsevolod Fedorov wrote: > Hello! > (* ^^^ This expression has type string -> unit but is here used with > type int -> unit *) Here is a simpler case: let use (f: 'a -> unit) = f 1; f "" The appearance of a 'free' type variable in the function signature implicitly implies the quantification: For all 'a . let use (f: 'a -> unit) = f 1; f "" which says, for each type 'a, there is a function 'use' .. Inside a particular instance of use, 'a is fixed. In Ocaml this design bug has been fixed for record and object fields: type t = { f: 'a . 'a -> unit } let use (wrap: t) = wrap.f 1; wrap.f "" Here the quantifier is explicit and binds only the type of the field f; and the record type t is entirely monomorphic. Note that the first interpretation is necessary in the first case, by considering: let f (x:int) = () use f; we simply cannot have the inner f "" type correctly. In the second case, you cannot instantiate the field with that f, because it is the wrong type -- the field requires the function to be polymorphic. With any luck this design bug will eventually be properly fixed, so you can write: let use (f: 'a . 'a -> unit) = f 1; f "" -- John Skaller Felix, successor to C++: http://felix.sf.net