RE: [PHP-DEV] Implementation help needed: Currying RFC

From: Date: Tue, 07 Jun 2011 13:43:50 +0000
Subject: RE: [PHP-DEV] Implementation help needed: Currying RFC
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
>    $apos = curry strpos(..., 'a'));
>    $apos();   // runtime error wrong param count?
>    $apos("bar"); // fine
>    $apos("bar", "foo"); // 'a' casted to long, used as offset?
>    $apos("bar", "foo", 0); // run-time error wrong param count?

I understand where this can be useful sometimes, but I disagree that this should be added as a
language feature. It is still possible to implement this (parameter positioning in your curried
function) using a function that returns a closure similar to the curry_left example in the RFC. One
possible method (inspired by the C++ system for doing the same thing) would be:

$apos = curry( 'strpos', _1(), 'a' ); // _1() returns a placeholder positioning
object

This isn't quite as nice as the proposed T_FILL, but on the other hand, it is more powerful
(parameters could change order) and isn't nearly as confusing as the RFC syntax (which looks
like perhaps strpos is being called in some strange way).

Of course, there is also always the regular old closure, which is far more explicit and leaves no
confusion about exactly what is being returned.

No offense to anyone who loves currying, but I don't see why this should be implemented. There
are plenty of good options available for achieving identical or better results without modifying the
language.

John Crenshaw
Priacta, Inc.


Thread (10 messages)

« previous php.internals (#53139) next »