From: skaller <skaller@users.sourceforge.net>
To: Tom <tom.primozic@gmail.com>
Cc: Caml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Function application implementation
Date: Thu, 26 Apr 2007 13:13:27 +1000 [thread overview]
Message-ID: <1177557207.8088.27.camel@rosella.wigram> (raw)
In-Reply-To: <c1490a380704251538i7d8086e7u9bb50d9d5d82cfd4@mail.gmail.com>
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 <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
next prev parent reply other threads:[~2007-04-26 3:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-25 22:38 Tom
2007-04-26 3:13 ` skaller [this message]
2007-04-26 8:52 ` [Caml-list] " 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=1177557207.8088.27.camel@rosella.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@yquem.inria.fr \
--cc=tom.primozic@gmail.com \
/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