Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102530 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71742 invoked from network); 29 Jun 2018 17:36:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2018 17:36:02 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.208.42 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.208.42 mail-ed1-f42.google.com Received: from [209.85.208.42] ([209.85.208.42:43576] helo=mail-ed1-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/02-52152-10E663B5 for ; Fri, 29 Jun 2018 13:36:01 -0400 Received: by mail-ed1-f42.google.com with SMTP id m21-v6so2963578eds.10 for ; Fri, 29 Jun 2018 10:36:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CFBS3gbiQZOlxL1M/MM/ZJaZwTKy0nKqsxx3oaRl3zw=; b=SI7FubdLbjqRajJJh/gGsj0+I0qA6TxU/Kv+VWhWzQqQW6GTNn55tKCHbMcKiQSxWs 9HfzBi7XA7dfI35KbTu47CS+dzyjBWgZS0n91YdXnbPW2fm3mWoaHuHcsS7eZ8FNMFji nc1ZwZhy9QdU3fhgoPHPWKctX9TJGzVosLSWryz+ewnBNBDJe+m665SHzetYPtyXFS+5 nk6NTA2Z7l3O+bKHg8N+5eU3vIR7I9+/ENsNIj/HJ2eHgr2l/AwADzxke0mj23olRsQp JPLkQeIR6WEzHGkYCFZ/3ROMdP5Uzyjczzvzcgf92KUPYNkY7bQvR2oZOlWjxKW7IT0h LfuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CFBS3gbiQZOlxL1M/MM/ZJaZwTKy0nKqsxx3oaRl3zw=; b=b1pjaop+uOyAULUbz7Sq18kP7/+5MWpyaIx5APvVugK5ubvKmKS+TFuE3Unl7dgjQ+ sbQs+Vn2cNsNvCmxh2SImSl4Ut44Wunt8gblfl3yeLu+9oOXM9nFPS8ppyngAYSH2cyx zYbgIk9DYIN4eybNYHWAwSEn33DIv6L0mH/XHfo/qSKKBUX89R964TBeVlpjhcBxqX7W fRTyziJctv7qL3vR7DMnDgNZ7zlnA6my3vpsbyYPgc9O39TTbPlkIrJPY6hH7hwwd8sI Vt/JgZNxewe/MxWJFKMSeiSg69wfKISUlP3KOBRw0Gtd846go6l3qUrXyq8ZW8wmWun0 wQXA== X-Gm-Message-State: APt69E298/b1oIwguFM0uu5yijch8hPYdAA2LP+FCOaKIc4IVkoHVX2U yVwlDMkgwYYuHhJkdp4PQs97OxCXFlvzlPX3UYY= X-Google-Smtp-Source: AAOMgpeHeRS1SRhxkvmFtpGsw5idVO+qRGINE6NjKFyGPiGpnnYGQdwurX7SxfIxvPj2DKMfE7qV146ybjkN4qggA98= X-Received: by 2002:a50:f4d2:: with SMTP id v18-v6mr3001694edm.162.1530293758781; Fri, 29 Jun 2018 10:35:58 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:8863:0:0:0:0:0 with HTTP; Fri, 29 Jun 2018 10:35:58 -0700 (PDT) In-Reply-To: References: Date: Fri, 29 Jun 2018 18:35:58 +0100 Message-ID: To: Levi Morrison Cc: Rudolf Theunissen , internals Content-Type: multipart/alternative; boundary="000000000000e4ecc7056fcb471f" Subject: Re: [PHP-DEV] [RFC] User-defined object comparison From: rowan.collins@gmail.com (Rowan Collins) --000000000000e4ecc7056fcb471f Content-Type: text/plain; charset="UTF-8" On 27 June 2018 at 19:24, Levi Morrison wrote: > This permits things such as NumPy to overload < to do an element-wise > comparison of the members; something like this: > > np.array([1, 3, 5, 7]) < np.array([2, 1, 6, 6]) > // evaluates to np.array([true, false, true, false) > In my opinion, this is exactly the kind of messy operator overloading we should avoid, but if we DO want it, then its purpose is to over-ride the syntax, not the meaning, of the operator; so "overloaded <=>" would NOT be the same as "overloaded comparison". I think it's fairly crucial that this proposal is NOT just about overloading operators, it's about overloading *behaviour* which occurs throughout the language, and as such I think this statement from the RFC is incorrect: > __compareTo is equivalent to <=> and __equals is equivalent to == If someone implements __compareTo() just to give some domain-specific meaning to the <=> operator, what will happen when someone passes those objects to sort()? If someone decides they want to return an object from __equals(), how will switch statements behave? And so on... Because of that, I would much rather these functions did enforce a return type. Note that __toString() generates an error for an incorrect return type when used, and __sleep() raises a Notice and serializes Null instead of the object. I think __compareTo() and __equals() could act more like a return type hint, and either throw a TypeError straight away, or attempt to coerce to the correct type and throw a TypeError on failure. Then, if we want the ability to override the <=> operator specifically, that can be added later, and users can return whatever type they want without breaking all the other places where __compareTo() is called. Regards, -- Rowan Collins [IMSoP] --000000000000e4ecc7056fcb471f--