Re: [RFC] Callable Types

From: Date: Fri, 22 Apr 2016 14:56:13 +0000
Subject: Re: [RFC] Callable Types
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-92644@lists.php.net to get a copy of this message
Hi! > On Apr 22, 2016, at 9:39 AM, Levi Morrison <levim@php.net> wrote: > >> Not much else to say, the syntax reads a bit weird/heavy being all in-line >> with the function signature but at the same time I can't imagine how else it >> would work that would be any better. > > As mentioned on Reddit and in the future scope section of union types, > we may want to introduce named type expressions: > > type IntReducer = callable(int, int): int; > > Which would also allow unions (if passed, of course): > > type Iterable = Array | Traversable; > > It would also allow for a general type-aliasing mechanism for single > names. This feature has been asked for in the past but I can't > remember the use-cases so this example is not very good: > > type Foo = SomeFoo; > > Then we just use the names where we would have put the expressions: > > function reduce(int $a, int $b, IntReducer $reducer): int { > return $reducer($a, $b); > } > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > While this is somewhat off-topic of this particular RFC, since we can already do general type-aliasing with use, use SomeFoo as Foo; perhaps similar syntax could be used for type expressions, eliminating the need for a new keyword. use callable(int, int): int as IntReducer; use array | Traversable as Iterable; Cheers! Aaron Piotrowski @trowski2002 trowski.com

« previous php.internals (#92644) next »