Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125249 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 7A5A51A00BD for ; Mon, 26 Aug 2024 01:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724634707; bh=htpBVELfRTmWS1Otv7LBM8l4zyINncUmpuV4Ad+nBzU=; h=Date:Subject:To:References:From:In-Reply-To:From; b=XxMq7nxUNJqpVSJ11Kx0Cylae8g838M7oF/8x/IXNTWyPvQU+X5JK3iqSqGUJ9DOY z5Z54crUJshw2gtQ5TrzFqj5xsNzzOcxJ6JS5emLWK/jSwi3IiBSmziB4HpIbMj4Y6 BvXfiphts1fDAThQxLiiUH0ZLSghRMVxlkfAIHVrPeX8v2UadGA6sB6zGdDt3q6VQr x3rwP7bKgiHxr9aNxugFaQQcUZGBAdZjLcYgQ6wn+AyJ6CFGJFb7WDpPe13AYtgmYE o7dCzQzj0tXg68iIFLM4JsU/kiHRugEcl5N4o4Y09ua2yybnXNg8trRZGQwBkAnA4l +yBz3/m7USrNg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3BF61180052 for ; Mon, 26 Aug 2024 01:11:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from emily.smtp.mailx.hosts.net.nz (emily.smtp.mailx.hosts.net.nz [43.245.52.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 26 Aug 2024 01:11:43 +0000 (UTC) Received: from 125-239-198-3-fibre.sparkbb.co.nz ([125.239.198.3] helo=[192.168.1.64]) by emily.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1siOEs-00Aw3T-0u for internals@lists.php.net; Mon, 26 Aug 2024 13:09:46 +1200 Message-ID: <28f8e671-c42c-4259-9b1d-b93795168fe9@varteg.nz> Date: Mon, 26 Aug 2024 13:09:37 +1200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] State of Generics and Collections To: internals@lists.php.net References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> <68b2f0c0-17e5-4aa4-8706-92f05aca2a95@app.fastmail.com> Content-Language: en-GB In-Reply-To: <68b2f0c0-17e5-4aa4-8706-92f05aca2a95@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Hosts-DKIM-Check: none From: weedpacket@varteg.nz (Morgan) To throw one more question into the pot, I'd like to raise the possibility of wanting typedefs. (To use the old C/C++ term, the latter also allows a "type alias" syntax that does much the same thing.) To use an example from the blog post: function f(List> $entries): Map {...} there need not be an explicit `Map` class; instead something like `type Map = List>;` (to use Rust syntax). So that one could write `Map` and have it *mean* `List>`. The blog example constructed a new Map given the List of Entries, but with the alias that would become a no-op. Meanwhile `BlogPost` might itself be an alias for `StructuredText<\DomDocument>`. Without the aliasing therefore we're looking at `List>` and who is going to write that over and over? It would muffle use of generics. I seem to recall that C#'s (or was it Java?) early support of generics didn't offer any sort of abbreviation mechanism and this lead to long awkward concrete types that no-one wanted to use. Calling them "aliases" implies that they're expanded before types are matched up. If `Wibble` and `Splunge` both ultimately expand to `Foo,Baz>` then they would be considered to be the same type, despite appearances. Since I expect that type aliases would become a desired feature, I would hesitate to allow/disallow making type inferences that could block their introduction. While the alias resolution would be an early stage that does mean it has to be able to identify any uses of a type in order to check whether it is a type alias. I can't think of any specific examples where this would be a problem, but it depends on how they actually end up looking - they should look like types.