Re: [RFC] Partial function application

From: Date: Mon, 17 May 2021 15:34:36 +0000
Subject: Re: [RFC] Partial function application
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-114503@lists.php.net to get a copy of this message
On Mon, May 17, 2021 at 5:16 PM Mike Schinkel <mike@newclarity.net> wrote: > > > On May 17, 2021, at 10:50 AM, Guilliam Xavier <guilliam.xavier@gmail.com> > wrote: > > > > On Mon, May 17, 2021 at 6:58 AM Mike Schinkel <mike@newclarity.net> wrote: > >> > >> > Well, I was thinking that by changing the proposed syntax we could >> achieve >> > what is proposed and a little bit more. >> > Also we wouldn't need to worry about the number of ? needed as >> arguments. >> > Since all we need is to mark the return type as partial (closure) on the >> > fly and grab hold of what is passed as arguments. >> > >> > There are some different syntaxes that come to my mind: >> > We could still use ? but outside of the arguments list? >> > ``` >> > $partial = xyx?(..); >> > $partial = ?xyx(..); >> > ``` >> > or maybe different symbols: >> > ``` >> > $partial = :xyz(..); >> > ``` >> > >> > We might be able to even cast the return type: >> > ``` >> > $partial = (?) xyz(..); >> > $partial = (partial) xyz(..); >> > $partial = (fn) xyz(..); >> > ``` >> >> Casting is another interesting approach that does feel more consistent >> with the existing language. >> >> Since it *is* creating a closure, wouldn't this make the most sense? >> >> $partial = (closure) abc(); >> > > Ouch! definitely NOT! > > >> $partial = (closure) xyz(?,24); > > > > Mind if I ask for you to elaborate on your aversion? > > Asking for general understanding, not to debate the point. > > -Mike > Sorry I was too "raw". I mean that the cast syntax $p = (whatever) f(); already very clearly means/does "evaluate f() [i.e. call it], then convert the evaluation result to whatever, then assign the conversion result to $p", and I think it would be a **very bad idea** to "reuse" the same syntax for something that wouldn't call f() immediately. I'm favorable to other syntaxes, but which don't look like a cast. Regards, -- Guilliam Xavier

« previous php.internals (#114503) next »