Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108426 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48084 invoked from network); 8 Feb 2020 22:05:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Feb 2020 22:05:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5CECD1804D2 for ; Sat, 8 Feb 2020 12:18:15 -0800 (PST) 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 8 Feb 2020 12:18:14 -0800 (PST) Received: by mail-wm1-f65.google.com with SMTP id f129so6359361wmf.2 for ; Sat, 08 Feb 2020 12:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=pcU1vhWQ5M4AAKlTRfxw4tvMdrqjhByHNKen4Psnd0A=; b=jq6tFxcHbr7PIBlvegl3FsFPK9DIaZFNX6KF776z8Mk7asA4fCLsyhTuQ/L0x2GESx +HYiZjsmVLOaZ5C2QtmAQUkV3xHiwApsXEZxQ5x3CZAuFkL2QN2GJWq3S3BIRDVw0iDS HDib/ML2mxDPzmXjkKdoRVb0mWYvsdXC7Y7Mq4DeY3ErHtDyOldZR9Bph8hPiyW1DWy4 Q46Csapih9ZGk9kyji05V4LK2yzoHIfOJJZIDKt0t0QYsLrBbD+yv/b7CZb1wBL4fCDA CIh61tgQAUJCfZZWXJxncsRv7DRHmcgyiObdilxYtlCKjSngmAXgoZFoSG4NwR8oy87u Y2qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=pcU1vhWQ5M4AAKlTRfxw4tvMdrqjhByHNKen4Psnd0A=; b=ciUjf1OFsDQEZMdHUpxhRLyOPwxro0obgZfRFF4M13A6BAQsQI0PwDhxorLzlvpgv0 8XJZmDRdQLe9NdTYGPRRu4JC+7zOxgT2wIOT86wkbHm6t30rkGdTpDUb/hfkrNPN4QjU +0v/4P73C/9w/Cju3DTcqYF3ezj8mFRXMOZ9VnMJBg4qlgkFtErPCh2grV2ZAdvv+w/1 WhnsDrryvYuMC7J8VJlIiMB6xcFAkVrm2aih0fc2SXrdmkEJCk3gUGu6OnX+fvdYCzOh 7tEEjzmIjL+dpCcp55Iz4LBatkwviiSgPgJjjCk13wJjXPOTxdqxrYIDiCqn56UOM1nR yS8Q== X-Gm-Message-State: APjAAAUDQjaQdO5xG/liqerHpzAzRJU7AekeEYTwHsxyC99wAGomIBOS VfG4IYXcls1o7q8R3tfhJdNajJmq X-Google-Smtp-Source: APXvYqw1exkYYq662Ok7IJ0KstTm2g6oNo+vejojAN9h9OMkle5Egid2IyptuwH06CdmgPvzLYwLAg== X-Received: by 2002:a1c:4857:: with SMTP id v84mr5573741wma.8.1581193091671; Sat, 08 Feb 2020 12:18:11 -0800 (PST) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id c13sm9371761wrx.9.2020.02.08.12.18.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 08 Feb 2020 12:18:11 -0800 (PST) To: internals@lists.php.net References: <00ea01d5d630$b18d4f20$14a7ed60$@gmx.de> <5e3c71cd.1c69fb81.2adcd.4101SMTPIN_ADDED_MISSING@mx.google.com> Message-ID: <1067445e-ed0b-8248-3d69-55737a6561fc@gmail.com> Date: Sat, 8 Feb 2020 20:18:09 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: <5e3c71cd.1c69fb81.2adcd.4101SMTPIN_ADDED_MISSING@mx.google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Operator overloading for userspace objects From: rowan.collins@gmail.com (Rowan Tommins) On 06/02/2020 20:06, Andrea Faulds wrote: > Haskell has a nice approach (probably some other languages have this > too) where it has typeclasses that contain related operators, which > means that e.g. if you want to overload +, your type needs to support > Num which also contains -, *, abs, the sign function, and conversion > from integers. > [...] > Also, Haskell also lets you just define arbitrary operators, which may > even look the same as the built-in ones if you really want to, so > maybe it's a bad comparison point :p It's interesting that in this sense, Haskell supports *both* of the "philosophies" of overloading that I mentioned in my last message. [1] I guess they're intended for different "levels" of programming in a sense: - From what I've heard Haskell tries to make as little distinction between "built-in" and "user-defined" as possible, so like Postgres, the actual "normal" definitions of the operators need to be defined by some low-level language feature. - On the other hand, that low-level feature is used to build a standard higher-level language, and that high-level language treats types as more important than symbols. In general, I think PHP is quite a high-level language, and doesn't tend to let you re-define core concepts to build new versions of the language, so the type-based approach to operator overloading feels more in keeping to me. If we had other low-level features - hygienic macros, meta-programming, meta-classes, that kind of thing - then defining new meanings for individual operator symbols would make more sense. [1] https://news-web.php.net/php.internals/108347 - not showing on https://externals.io for some reason Regards, -- Rowan Tommins (né Collins) [IMSoP]