caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Chris Hecker <checker@d6.com>
To: qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk), caml-list@inria.fr
Subject: Re: [Caml-list] currying...
Date: Tue, 06 Mar 2001 15:23:50 -0800	[thread overview]
Message-ID: <4.3.2.7.2.20010306150210.037887a0@shell16.ba.best.com> (raw)
In-Reply-To: <slrn9aam9a.qn.qrczak@qrnik.zagroda>


>A library which has different behavior depending on the physical
>arity of functions it works on is broken. 

It's not going to have different behavior, and it's not an optimization.  The library has to know because it has to know when to call a C function from another C function and it has to tell caml when to call it from caml.

Say I give a prototype to the library that's int -> int -> int -> int and I expect the library to give me back a closure that thunks to a c function.  Two things (at least) have to go on here:

- the library needs to know whether this is "int (*)(int,int,int)" or "int (*(*)(int))(int)" (or something else) so that it can create a closure to pass back to caml that has the right physical arity so that caml will call it and expect the right return type

- the library also needs to know the above so that it can call the linked c function correctly with the right number of arguments (this is analogous to the cast you have to make in C when you GetProcAddress/dlsym)

Since this is all happening dynamically, I need to be able to deduce the physical arity of the functions at runtime.

> Why? "Uncurrying" anything at all is an optimization. A straightforward
>implementation would just apply arguments one at a time, allocating
>a closure at each step.

Yes, I understand allocating the closure and it appearing like there's a bunch of 1 parm functions, but at some point the _actual_ function that does the work has to be called, so the implementation must know.  The only alternative is real partial evaluation to reduce the actual physical arity (meaning the function is specialized on its partially applied parameters and regenerated as an arity - 1 function), which is just way too complicated for caml or any other production language, I'd assume, so caml must just allocate a bunch of closures until it gets enough to call the original physical function.

> No code should rely on where it is, unless it hides this under its
>cover too and presents a unified interface to the outside. Do you
>really have a case where you can use this fact to enable better
>performance?

Again, it's not performance.  The C side has to know for me to write this library, as I said above.  All this will definitely be hidden, so you'll be able to pass partially applied functions and partially apply the returned functions, so the programmer won't know.  But there'll be a lot of stuff going on underneath to make this work.

Chris


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  reply	other threads:[~2001-03-06 23:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-06  9:39 Chris Hecker
2001-03-06 10:22 ` Thomas Colcombet
2001-03-06 10:33 ` Bruce Hoult
2001-03-06 10:50 ` Remi VANICAT
2001-03-06 16:31 ` Xavier Leroy
2001-03-06 17:41   ` Chris Hecker
2001-03-06 18:43     ` Sven LUTHER
2001-03-06 19:09     ` Marcin 'Qrczak' Kowalczyk
2001-03-06 20:14       ` Chris Hecker
2001-03-06 21:39         ` Marcin 'Qrczak' Kowalczyk
2001-03-06 23:23           ` Chris Hecker [this message]
2001-03-06 23:45             ` Marcin 'Qrczak' Kowalczyk
2001-03-07  1:10               ` Chris Hecker
2001-03-07  8:44                 ` Marcin 'Qrczak' Kowalczyk
2001-03-06 23:51             ` Chris Hecker
2001-03-06 10:16 Adam Granicz

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=4.3.2.7.2.20010306150210.037887a0@shell16.ba.best.com \
    --to=checker@d6.com \
    --cc=caml-list@inria.fr \
    --cc=qrczak@knm.org.pl \
    /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;
as well as URLs for NNTP newsgroup(s).