Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93468 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44944 invoked from network); 24 May 2016 06:28:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 May 2016 06:28:33 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.182 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.217.182 mail-lb0-f182.google.com Received: from [209.85.217.182] ([209.85.217.182:33761] helo=mail-lb0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/31-37212-194F3475 for ; Tue, 24 May 2016 02:28:33 -0400 Received: by mail-lb0-f182.google.com with SMTP id k7so2070581lbm.0 for ; Mon, 23 May 2016 23:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=bU+4P1ECw2l8gJ6s8CAg3Ux+VW3wPLBI0lrNXdAEmSQ=; b=0dWJ7Jrr5QjPo3xAaTD7ohXnb6EbT3uIt2O0rNFNIWj4T23l12gxbfmul+WU9hIjSs K+Ex8d7SCfT3L6v9fLCzlsYwL/By5WwHZ+vWXWNvIk2MwgSkg06Z+jIrHi9tR3jZjthT s7kV+s7g7oHsSXf6dMSQ+BLHiLGs32YJ6vTSxR5RzR1r/8dM2Kv0oUbcnJTEYb+mBiPX oOzYS7twp8jLAyo8dYPUD/kFQPujeRRF0m6QIWZNYmYoHw10GcsC3TVEaDuyiS6bDWLf V/jBBvUpWikWqzgyCogYlP040FDgzYAIsPIJETh2i1tOaBzuvgoyqpzP2UEaS8knPkdh zN/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=bU+4P1ECw2l8gJ6s8CAg3Ux+VW3wPLBI0lrNXdAEmSQ=; b=IWfhXJFBGQHza6QSq7lK5FuRUv8GSvNwyklY6m0TlIfaUUXCynshBbbL1PXzOfXJqB qd9RdFZBMkMN/J5Y/wyJxIFjt1mYsTkxkVYBrDcLu7NHA2wWM+UPEmQbNDeooSkKDmBU qHUPgZx4YsQXj2Ht/uvg8sJDiTf/IFxaekzi9SuA/OsyheS124IWDbUtHZyWGPu782rS BrtafpHFyOgHoyVKiFbdYumtAHUQtnZKdWsgI24SbYYnXrKD15T2VCzQUSQO0hjpVjV8 71ime8m/pIhRmQTZKLKHwoyLZ2RV4TU9QdeHqVbACByhqF9wepU5NsDE050IRwzVRG2o eUsQ== X-Gm-Message-State: AOPr4FXpXKxBERZ4z52O828dBxfXQtDIZHGhkVcVemqZZ+S32N6PXDgfu0skEU2uAs6A7g== X-Received: by 10.112.63.136 with SMTP id g8mr7148514lbs.135.1464071310265; Mon, 23 May 2016 23:28:30 -0700 (PDT) Received: from nikita-pc (broadband-95-84-234-130.nationalcablenetworks.ru. [95.84.234.130]) by smtp.gmail.com with ESMTPSA id dw6sm228246lbc.10.2016.05.23.23.28.28 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 23 May 2016 23:28:29 -0700 (PDT) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "Dan Ackroyd" Cc: "internals@lists.php.net" References: Date: Tue, 24 May 2016 09:28:30 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.17 (Win32) Subject: Re: [PHP-DEV] [RFC] [Vote] Callable types (now: Callable prototypes) From: inefedor@gmail.com ("Nikita Nefedov") On Tue, 24 May 2016 02:24:12 +0300, Dan Ackroyd wrote: > Hi Nikita, > > On 23 May 2016 at 15:27, Nikita Nefedov wrote: >> With this message I'd like to go to vote >> with the Callable prototypes RFC targeted at 7.1: >> https://wiki.php.net/rfc/callable-types > > To explain my vote - I think we definitely need to be able to specify > the signatures of callables in PHP, and I would very probably support > either a 'typedef' RFC, or an expansion of current functional type > (i.e. invokables) to be easier to use with functions, but I just > couldn't possibly vote for an RFC that means people would sometimes > write code similar to this: > > function foo(int $a, int $b, > callable(callable(callable(callable(int, int):int $zebranky, int):int > $pik, int):int $fot, int):int $zot): int { > return $zot($a, $b); > } > > to use the feature of the RFC. > > I realise that is an extreme case, but I think that splitting where a > type is defined (with a name) and the place where it is used to be > separate places, is one of the things that the design of PHP got > right. It makes it easier to read code, even if it makes the language > feel less 'powerful' than other languages. > > cheers > Dan Morning Dan, I think we definitely would need type aliases. But I also hoped for union types to get in, so that after these two we could have another RFC that would do typedefs for callables and for unions. Doing typedefs for callables only seems too narrow. People would probably vote 'no' for that RFC because apart from creating new syntax for callables it would also create a flavour of typedef that works in limited scope only. And that seems completely fair, typedef is another feature. And even with typedefs I see no reason not to support inline callable prots. Do you remember 'Arbitrary expressions' RFC? I look at it just like at expressions, and I think there's a need for any possible type to be expressed directly in a parameter typehint. Making code more readable would be a responsibility of a user who would decide whether he needs to use function signatures or not. Regarding Joe's functional interfaces, I wish they were passing vote. They can be a nice addition (and a pretty simple one) to the language. I also think they are not related to this RFC, as their usage is completely different... What I am aiming at with this (and possibly next) RFC is to make function composition work better and functional interfaces don't touch this subject at all. The fact that function needs to opt-in and the fact that the signature of a function needs to be completely same as in interface (so no variance) makes it useless in cases where callable prototypes should be used instead. > I realise that is an extreme case, but I think that splitting where a > type is defined (with a name) and the place where it is used to be > separate places I think so too but "callable(int): int" is not defining a type, it is using it. On the other hand "callable" here is a type constructor. If we would have generics of some form this would be similar to: "Function" where you don't define a type but you create it passing "int, int" arguments to a type constructor (or a template, or a generic class) which results in a type in the end. When you get parametrized types there's a natural need for parameterizing them in place...