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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id BB8E5BC69 for ; Thu, 26 Apr 2007 05:13:31 +0200 (CEST) Received: from ipmail01.adl2.internode.on.net (ipmail01.adl2.internode.on.net [203.16.214.140]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3Q3DTrA028466 for ; Thu, 26 Apr 2007 05:13:30 +0200 X-IronPort-AV: E=Sophos;i="4.14,452,1170595800"; d="scan'208";a="119559504" Received: from ppp8-148.lns1.syd7.internode.on.net (HELO [192.168.1.201]) ([59.167.8.148]) by ipmail01.adl2.internode.on.net with ESMTP; 26 Apr 2007 12:43:28 +0930 Subject: Re: [Caml-list] Function application implementation From: skaller To: Tom Cc: Caml List In-Reply-To: References: Content-Type: text/plain Date: Thu, 26 Apr 2007 13:13:27 +1000 Message-Id: <1177557207.8088.27.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 463018D9.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 0200,:01 compiler:01 ocaml:01 stack:01 compiler:01 sourceforge:01 wrote:01 caml-list:01 functions:01 expression:02 evaluates:02 evaluates:02 functional:02 guess:04 compiled:04 On Thu, 2007-04-26 at 00:38 +0200, Tom wrote: > I have a question about how are function applications compiled. In > particular, how does the program "know" the difference between f and g > in: > But obviously, this cannot be the case, as the functions aren't > determined in advance at all call sites (in a functional language). > How does the compiler deal with that? It knows the type of the function expression, and that is all that is required. Incidentally Ocaml evaluates right to left. So f x y z will be roughly: push (eval z) push (eval y) push (eval x) push (eval f) apply apply apply I guess this simple stack protocol explains why it evaluates right to left not left to right. The real compiler will of course do optimisations not shown above. -- John Skaller Felix, successor to C++: http://felix.sf.net