From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA01239; Wed, 7 Mar 2001 00:23:26 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA22176 for ; Wed, 7 Mar 2001 00:23:26 +0100 (MET) Received: from smtp4-cm.mail.eni.net (smtp4-cm.mail.eni.net [216.133.226.137]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f26NNOD27579 for ; Wed, 7 Mar 2001 00:23:24 +0100 (MET) Received: from checkerlap.d6.com (node-d8e9cca2.powerinter.net [216.233.204.162]) by smtp4-cm.mail.eni.net (8.9.3/8.9.3) with ESMTP id PAA03774; Tue, 6 Mar 2001 15:23:17 -0800 Message-Id: <4.3.2.7.2.20010306150210.037887a0@shell16.ba.best.com> X-Sender: def6@shell16.ba.best.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Tue, 06 Mar 2001 15:23:50 -0800 To: qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk), caml-list@inria.fr From: Chris Hecker Subject: Re: [Caml-list] currying... In-Reply-To: References: <4.3.2.7.2.20010306012957.00c7cf00@shell16.ba.best.com> <4.3.2.7.2.20010306012957.00c7cf00@shell16.ba.best.com> <4.3.2.7.2.20010306093019.00e181f0@shell16.ba.best.com> <4.3.2.7.2.20010306120843.037813b0@shell16.ba.best.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >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