From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 96630BC6B for ; Wed, 27 Jun 2007 12:14:21 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.170]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5RAELS9013135 for ; Wed, 27 Jun 2007 12:14:21 +0200 Received: by ug-out-1314.google.com with SMTP id o2so266049uge for ; Wed, 27 Jun 2007 03:14:21 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=NGSPti5xmWRDaKgVWddgjThxn9F+LKUDh6NkICSY97d3Gq7QBMCN0owkWeFu8kqQJXIXTcxJ5SZ5XAivG3OJv0qjD4d8fmUrsGrlq5lOqCRkYGnHtUaKEDjsxoncYCo7atOH1YZLDlK8t23xx+Q5t9WBf67OYzSK3z7dF53KEm0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=Qotrf2dO6hEy74fwCyTE57PsAXFCr6UJst1buP0KpidAxu44fZzv5CWGpmppvQsVPXpBpUCqopXr5mDjV3xOCpLyjyRbcobwV1uMzvMr2NlRnMC2q5n2fMAwXe3TC8mDQXR3z9TVXxvIl1mR+iCm5kALupo32317w0cUPCm0/4Q= Received: by 10.67.101.8 with SMTP id d8mr1074826ugm.1182939261020; Wed, 27 Jun 2007 03:14:21 -0700 (PDT) Received: from ?83.248.135.4? ( [83.248.135.4]) by mx.google.com with ESMTP id 24sm431179ugf.2007.06.27.03.14.20 (version=SSLv3 cipher=RC4-MD5); Wed, 27 Jun 2007 03:14:20 -0700 (PDT) Message-ID: <4682387C.5070600@lix.polytechnique.fr> Date: Wed, 27 Jun 2007 12:14:20 +0200 From: Arnaud Spiwack User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] let rec and polymorphic functions References: <000e01c7b896$d3372440$6a7ba8c0@treble> <200706271005.10837.jon@ffconsultancy.com> In-Reply-To: <200706271005.10837.jon@ffconsultancy.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: Arnaud Spiwack X-Miltered: at discorde with ID 4682387D.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; lix:01 ad-hoc:01 polymorphism:01 recursion:01 val:01 recursive:01 val:01 printf:01 ad-hoc:01 specifier:01 ocaml:01 ocaml:01 run-time:01 higher-order:01 recursive:01 Jon Harrop a écrit : > There are many problems with this. Google for ad-hoc polymorphism, polymorphic > recursion and generic printing. > > On Wednesday 27 June 2007 09:40:31 David Allsopp wrote: > >> out "TEST"; >> > > val out : string -> unit > Actually it seems to infer properly "out : (unit, out_channel, unit) format -> unit". So the magic is pulled here (which surprises me a lot, but well). The problem seems more related to the fact that mutual recursive function are monomorphic. > >> out "%d" 0; >> > > val out : format -> int -> unit > > As printf is ad-hoc polymorphic, you must supply the format specifier > immediately and OCaml will generate a custom printer for you. OCaml does not > use run-time types so you cannot have a generic print function: you must > specific print functions for each of your (possibly higher-order) types. > > Also, recursive calls ossify the function to a monomorphic type, so you cannot > do polymorphic recursion in OCaml. There are workaround using recursive > modules or objects but I don't think this is what you want here. > >