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.2 required=5.0 tests=AWL,HTML_MESSAGE,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 B25AEBC69 for ; Thu, 26 Apr 2007 00:38:05 +0200 (CEST) Received: from mu-out-0910.google.com (mu-out-0910.google.com [209.85.134.188]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3PMc4bh017557 for ; Thu, 26 Apr 2007 00:38:04 +0200 Received: by mu-out-0910.google.com with SMTP id w9so399600mue for ; Wed, 25 Apr 2007 15:38:04 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=md1SLdACcmL3sQJJxss/yST0bPjPZTI/7R2wMzT0usJtDxI2zAg+HAVQMfEWDsVSeYmcSibX+BnCZa21OutN2tR6AxaOhvTGsq94Pe+qYlMoZvb/dFjfVg/fkymeEp7crVQ7AsAqLlMr9Wz4shfZx+n8qypIk8t+BMmPBAM1Fz0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=myN0+xtzNT4XDafIieEfU+Ti4eW5bd4uUoZFOfkmoDUS8oqFagfUa7H48W2Jy4lM0OJtSy5/dcOTB/Hx6YfYuH9zYec4VpLNoZLvqz7swevwziH9QURHXaFiVjkdz+krTtfAVY28eEejqY8Ld1Bt6+FMgE5sYzQJXxpM219l9a8= Received: by 10.82.100.1 with SMTP id x1mr2188276bub.1177540684114; Wed, 25 Apr 2007 15:38:04 -0700 (PDT) Received: by 10.82.157.14 with HTTP; Wed, 25 Apr 2007 15:38:04 -0700 (PDT) Message-ID: Date: Thu, 26 Apr 2007 00:38:04 +0200 From: Tom To: "Caml List" Subject: Function application implementation MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_131114_20147186.1177540684080" X-j-chkmail-Score: MSGID : 462FD84C.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 462FD84C.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; compiler:01 compiler:01 compile:01 compile:01 functions:01 functions:01 int:01 int:01 closure:01 closure:01 functional:02 functional:02 W4:96 W4:96 let:03 X-Attachments: cset="UTF-8" cset="UTF-8" ------=_Part_131114_20147186.1177540684080 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline I have a question about how are function applications compiled. In particular, how does the program "know" the difference between f and g in: let f w x y z = w + x + y - z let g w x y = let m = ref (w + x + y) in function z -> !m - z print_int (f 1 2 3 4) print_int (g 1 2 3 4) According to my logic, the first call should compile something like push 1 push 2 push 3 push 4 call function_f and the second like push 1 push 2 push 3 call function_g // the return value, new function closure, is (for example) in register A push 4 call A 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? (I am simplifying here, disregarding the matters of closure construction and deconstruction, along with environments. However, the refuced example still causes me problems.) - Tom ------=_Part_131114_20147186.1177540684080 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline I have a question about how are function applications compiled. In particular, how does the program "know" the difference between f and g in:

let f w x y z = w + x + y - z

let g w x y =
     let m = ref (w + x + y) in
     function z -> !m - z

print_int (f 1 2 3 4)
print_int (g 1 2 3 4)

According to my logic, the first call should compile something like
   push 1
   push 2
   push 3
   push 4
   call function_f
and the second like
   push 1
   push 2
   push 3
   call function_g   // the return value, new function closure, is (for example) in register A
   push 4
   call A

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?

(I am simplifying here, disregarding the matters of closure construction and deconstruction, along with environments. However, the refuced example still causes me problems.)

 - Tom
------=_Part_131114_20147186.1177540684080--