From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q1O1Fb4m006025 for ; Fri, 24 Feb 2012 02:15:37 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AloHACfkRk+FBoIF/2dsb2JhbABDgxKwS4FzAQEEAScZAwE1AQEDCwtGVwaIFKwchDCGSgEGjHEBChMXCAsDDw0CCQkQAgUDAoUcgz1jiFGMa4VdjR8 X-IronPort-AV: E=Sophos;i="4.73,473,1325458800"; d="scan'208";a="132677929" Received: from rabbit.math.nagoya-u.ac.jp (HELO mailhost.math.nagoya-u.ac.jp) ([133.6.130.5]) by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Feb 2012 02:15:30 +0100 Received: from mailhost.math.nagoya-u.ac.jp (localhost [127.0.0.1]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 5A63762BA; Fri, 24 Feb 2012 10:15:28 +0900 (JST) Received: from mailhost.math.nagoya-u.ac.jp (camel-172.math.nagoya-u.ac.jp [172.16.254.4]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 286B43A13; Fri, 24 Feb 2012 10:15:28 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=math.nagoya-u.ac.jp; h= subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; s=alpha; bh=6arP1/CMUq3RXPeMf3AYVpQeGpY=; b=bWiWPafV/onJGU/pfCC3CJA5fv9a j4MGNIA1ALjnxUbvRo8BrY5sqooRISN0accHUzKStlJKLOOUbZ64RRLhkrQzzLaD gUA8m/iD9SA3DJoKk9yLFQMvea5mDbawtHlhI+7YrsXFrOLBMZBzbi2IEJBDX3TG yEEjGnCMA5safzA= DomainKey-Signature: a=rsa-sha1; h=Received:Subject:Mime-Version:Content-Type:From:In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=IunCWCMG3flkv1IckVUPu4X7ikcfX6ktupySap1sU+zGLhLc660WLM7/OECKKRfmso1FtHE17pkBvssWE7lwuCJwZufmPoNHjMN1/WNtjjg7FpRM+lrSTyYDehc6SwE8eojXFebzPAdtII/GTHE5VK7pMA8jdjtufySqBneedWI=; c=nofws; d=math.nagoya-u.ac.jp; q=dns; s=alpha Received: from [172.16.30.37] (unknown [172.16.30.37]) by mailhost.math.nagoya-u.ac.jp (Postfix) with ESMTP id 1F7AF3974; Fri, 24 Feb 2012 10:15:28 +0900 (JST) Mime-Version: 1.0 (Apple Message framework v1257) Content-Type: text/plain; charset=windows-1252 From: Jacques Garrigue In-Reply-To: <4F468B23.6020006@mcmaster.ca> Date: Fri, 24 Feb 2012 10:15:44 +0900 Cc: caml-list@inria.fr Message-Id: <4EEA9299-CB06-448B-B3D4-70B6F07ED08D@math.nagoya-u.ac.jp> References: <4F468B23.6020006@mcmaster.ca> To: Jacques Carette X-Mailer: Apple Mail (2.1257) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id q1O1Fb4m006025 Subject: Re: [Caml-list] inlining/eta-expansion question On 2012/02/24, at 3:53, Jacques Carette wrote: > What difference is there, if any, between > let plus = (+) > and > let plus = fun a b -> a + b > ? > > I know that, operationally, these are identical. What I am wondering is, do applications of 'plus' always compile down to the exact same thing? > > In code that I am writing, due to interactions with the value restriction, I have to eta-expand all my definitions. So I am wondering what cost I will have to pay for the 'genericity' of my code. > > Jacques For your example: they are identical, since (+) is a primitive, and will be eta-expanded anyway if all arguments are not provided. But this is is not the case for normal functions: in general eta-expansion is not compiled away, as the function itself might have side-effects in partial applications, so the eta-expanded form might have different semantics. With ocamlopt inlining may solve that at the call point, but not all functions can be inlined… Jacques Garrigue > ocaml -dlambda OCaml version 3.13.0+dev11 (2012-01-26) # let plus = (+);; (let (plus/1038 (function prim/1040 prim/1039 (+ prim/1040 prim/1039))) (apply (field 1 (global Toploop!)) "plus" plus/1038)) val plus : int -> int -> int = # let plus a b = a+b;; (let (plus/1041 (function a/1042 b/1043 (+ a/1042 b/1043))) (apply (field 1 (global Toploop!)) "plus" plus/1041)) val plus : int -> int -> int = # let plus' a b = plus a b;; (let (plus/1041 (apply (field 0 (global Toploop!)) "plus") plus'/1044 (function a/1045 b/1046 (apply plus/1041 a/1045 b/1046))) (apply (field 1 (global Toploop!)) "plus'" plus'/1044)) val plus' : int -> int -> int =