Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92644 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43417 invoked from network); 22 Apr 2016 14:56:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Apr 2016 14:56:19 -0000 Authentication-Results: pb1.pair.com header.from=aaron@icicle.io; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=aaron@icicle.io; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain icicle.io designates 199.38.81.6 as permitted sender) X-PHP-List-Original-Sender: aaron@icicle.io X-Host-Fingerprint: 199.38.81.6 mercury.negativeion.net Received: from [199.38.81.6] ([199.38.81.6:60699] helo=mercury.negativeion.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4D/57-14036-29B3A175 for ; Fri, 22 Apr 2016 10:56:18 -0400 Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 06BD33846EA0; Fri, 22 Apr 2016 10:56:16 -0400 (EDT) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NNGIvkE3_EVa; Fri, 22 Apr 2016 10:56:14 -0400 (EDT) Received: from jupiter.local (unknown [173.225.150.231]) by mercury.negativeion.net (Postfix) with ESMTPSA id EFC9B3846E92; Fri, 22 Apr 2016 10:56:13 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) In-Reply-To: Date: Fri, 22 Apr 2016 09:56:13 -0500 Cc: internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <5719EA39.2070408@seld.be> To: Levi Morrison X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV][RFC] Callable Types From: aaron@icicle.io (Aaron Piotrowski) Hi! > On Apr 22, 2016, at 9:39 AM, Levi Morrison wrote: >=20 >> 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. >=20 > As mentioned on Reddit and in the future scope section of union types, > we may want to introduce named type expressions: >=20 > type IntReducer =3D callable(int, int): int; >=20 > Which would also allow unions (if passed, of course): >=20 > type Iterable =3D Array | Traversable; >=20 > 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: >=20 > type Foo =3D SomeFoo; >=20 > Then we just use the names where we would have put the expressions: >=20 > function reduce(int $a, int $b, IntReducer $reducer): int { > return $reducer($a, $b); > } >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 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=