Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120088 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32950 invoked from network); 20 Apr 2023 20:02:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Apr 2023 20:02:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C7DA41804D5 for ; Thu, 20 Apr 2023 13:02:47 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 20 Apr 2023 13:02:47 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 0402D5C012A for ; Thu, 20 Apr 2023 16:02:47 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute4.internal (MEProxy); Thu, 20 Apr 2023 16:02:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1682020966; x= 1682107366; bh=gKjovb0NfVldEb2dO8tx5uTQiMLmWohzwjsUynQ9RlU=; b=q cUPBjrEdTCTssa1JXAFQblniurECERycJtNHkfZl/ZTzBCAQ53p1IRf27UlEq1lD d+0764PKscuN24Uu/ymvRNxoo8guDYMiQBfp2NxrlIU6F/RkWBc9cYvLRwPcgjaO WH6hrIahy9JbLvzrCgeiuq9fgH9iOxDW/untjhhDx6xYncpdp+1t2+pJmtdsJqSm GKzHEp90roGRKR1YoTVwmAQZH1ZdqnUGZjBWEdf144e7tQq2ib4Pkckqbq/MNzcQ TBs7HDm6j1Sno/LcIAMo1HMzO9/K4/rW0aSGCxRacVknuIQOmFELcnKHVRTvP4d+ FUsknPZP1D7MdtleTX+Yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1682020966; x=1682107366; bh=gKjovb0NfVldE b2dO8tx5uTQiMLmWohzwjsUynQ9RlU=; b=GTc1CZsjqW5SWlTzhUhvOqw+JY3ax 74iIAUl7WeQQUFZvKJSF98opB0z/LyAQG4GG4ZD+xYKXszWEMMSs91ac3Ak1/nAx 1s3aoihTpHzHt96IZKxW9o6kwwoaELMe5NnW/Hw3jQeZI3xtJ27ha7THu/gWm3gI ltdNL8hpWubxpLSsIJHBRxoTJQVzKJGc7IEWVnRd8hBFdFd3t2vi8dtza02o9dHe Qh+GCgmepqqL83XNhQvpcMF8JwolkgiIg13E863Rb+fjRYLPNimXz0nV7TDFipKc zbpLJZKy4t7jxZL42D6k9EAZ3dPlhV/ipVPWgr43TonCPIKUJnXAFSo3Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedtvddgudegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 99B281700089; Thu, 20 Apr 2023 16:02:46 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-372-g43825cb665-fm-20230411.003-g43825cb6 Mime-Version: 1.0 Message-ID: <97fc7858-39c0-45ee-96e2-e049f227f52f@app.fastmail.com> In-Reply-To: References: <6b5de716-d769-4f0b-b3e6-5a5a211f035a@app.fastmail.com> Date: Thu, 20 Apr 2023 20:02:22 +0000 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [Discussion] Callable types via Interfaces From: larry@garfieldtech.com ("Larry Garfield") On Thu, Apr 20, 2023, at 7:30 PM, Dan Ackroyd wrote: > On Thu, 20 Apr 2023 at 18:25, Larry Garfield wrote: >> >> Hi folks. This is a pre-discussion, in a sense, before a formal RFC. > > > Hi Larry, > > The "Allow casting closures into single-method interface > implementations" one seems a complete non-starter, as that seems > really hard to work with. You'd have to do lots of "wiring up" to do > any significant amount of programming. That's my concern as well, and part of what led me to suggest the structural typing approach. > "Allow Closures to Declare Interfaces they Implement" > > That sounds bad as it doesn't allow arbitrary functions to be used as callables. Yes. Which is why I think it would make the most sense when combined with one of the other two options, so it's a sort of performance optimization for the general case. >> We feel that the interface-based approach is strong > > All three of them are using interfaces...? I'm referring to the general idea of this thread, which is "an interface with __invoke is how you define a callable type." Everything else here is a variation on that basic premise. > But if you mean the "Structural Typing for Closures" one, then I'd > probably agree. But as currently proposed it seems like a hack, that > would be predictably regrettable in a couple of years. In what way? >> and a good way forward for getting typed callables >> without a bunch of dependent features needed first. > > Maybe list what you think the dependent features are, so that there > isn't confusion about them, but I suspect that we're going to not > agree on how languages should be designed and evolve. Mainly the type alias question. Every time I see callable types discussed, it immediately sidetracks into "how do we make that less fugly to write, because callable types are naturally very verbose?" That leads directly to typedefs/type aliases, which take one of two forms: type TwoInts = callable(int $x, int $y): int type LinkedResponse = ResponseInterface&LinkCollectionInterface which raises autoloading questions and means a dependency on a type defined in another package, in many cases. Or: use callable(int $x, int $y): int as TwoInts use ResponseInterface&LinkCollectionInterface as LinkedResponse Which would be file-local, much like class "use" statements are. That avoids the autoload and dependency problem, at the cost of having to retype that frickin' thing in every file where it's relevant. In many cases, that could be dozens or hundreds of files repeating that line. And that's where the discussion usually dies off. As noted, this is still a form of structural typing, which means the function call process necessarily gets more complex (for callables). Using existing interfaces for callable definitions side steps the implementation challenges of type aliases/typedefs, since once you have an object tagged with an interface (via any of the mechanisms described), its behavior is already very well-defined and predictable. > Although I really want to see typed callables, and other forms of type > aliasing, as they would be huge improvements in being able to write > code that is easy to reason about and maintain, I don't want to seem > them as soon as possible, having taken short-cuts against good > language design. > > "No is temporary, yes is forever". I'm happy to see forward motion on any front. If the result of this thread is that someone gets incentivized to finally figure out callable types for realsies without an interface, I'd sleep happy with that result. But this gives us something concrete to chew on, which we have so far lacked. --Larry Garfield