From: Tom <tom.primozic@gmail.com>
To: "Caml List" <caml-list@yquem.inria.fr>
Subject: Function application implementation
Date: Thu, 26 Apr 2007 00:38:04 +0200 [thread overview]
Message-ID: <c1490a380704251538i7d8086e7u9bb50d9d5d82cfd4@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 938 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 1215 bytes --]
next reply other threads:[~2007-04-25 22:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-25 22:38 Tom [this message]
2007-04-26 3:13 ` [Caml-list] " skaller
2007-04-26 8:52 ` Tom
2007-04-26 9:17 ` skaller
2007-04-26 9:25 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c1490a380704251538i7d8086e7u9bb50d9d5d82cfd4@mail.gmail.com \
--to=tom.primozic@gmail.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox