Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92301 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41700 invoked from network); 14 Apr 2016 14:27:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2016 14:27:29 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.194 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.192.194 mail-pf0-f194.google.com Received: from [209.85.192.194] ([209.85.192.194:33045] helo=mail-pf0-f194.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/52-25796-0D8AF075 for ; Thu, 14 Apr 2016 10:27:28 -0400 Received: by mail-pf0-f194.google.com with SMTP id e190so7310202pfe.0 for ; Thu, 14 Apr 2016 07:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=TryGZl5zXWDBFwsq9jg3fEw+XfqNBGAYiuLiVRILy8o=; b=G6e4PWD/ZmWjdptlr4SpLwpsShNrotsYn1nVedCOQIPhhJwg8hHpMGXGrjHrrfqAjY HYzVClQXyH/xsh2JXYHC611AlTN/5mZj+vm2c3Hr2EfYJ/35ph/oxZXlkEZv9NBduAkA 672cCVGtxuMJxhNCPYSsDR5vhi9etCx5TL6mEnnVGwIj/e/ndBPKHdkq7iC2HVHlysiK ftY8zxrHI31l9Ra4hG+Zael77P48p+54gncmi8DdHLqfcYrgVzcRNOGwFb/PDPfa2Uuq nJZ+vYnPy0GQdMHk/DTVCt2NY2SxtNFlLZiL60yvrY53lzK8wcQnU0FY8sBfuIqNix8U 5AgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=TryGZl5zXWDBFwsq9jg3fEw+XfqNBGAYiuLiVRILy8o=; b=Og7uI58/sSdziexls3e+UH+1vuRfns/+FnHDg/zeYzOznVxmfHy+udfXGAOY0e0cSF CPCr9lSZrrcvP9MoBzk0eeuzNfGt30XfpQHKjJOxHdw+szhoLiIHbvQZr6M2ICZa0Y/g WRFL7HUPEpCqwntA+od1LfT1rsTkzitIErJf44nF1l8NiJB0vsJHXUCC0YnZj+BULKee aBdfI1Lh2JMQkJoc78/xEO/RmH+GrJ4+w0fl7kPdvQVNXA/4l87WkJeFNMg3EmoEz1Td DUSD0XxCONSdV7gv0JInlq4xFj4ZYEikaCyV6SQ28U93PB7zPRFi2ErZxGDKqKjZFfjT IjkQ== X-Gm-Message-State: AOPr4FXT7Tu0o0WGq7MonYiHLhwMHkI6qKVhoClOpBPm7DumrIqtA12MibpAAlkdGPl2nOR+EHvPgbYjuhTG6g== MIME-Version: 1.0 X-Received: by 10.98.86.77 with SMTP id k74mr21162804pfb.28.1460644045839; Thu, 14 Apr 2016 07:27:25 -0700 (PDT) Received: by 10.66.163.232 with HTTP; Thu, 14 Apr 2016 07:27:25 -0700 (PDT) In-Reply-To: References: Date: Thu, 14 Apr 2016 08:27:25 -0600 Message-ID: To: Davey Shafik Cc: Derick Rethans , Lin Yo-An , internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Union Types From: morrison.levi@gmail.com (Levi Morrison) > Also, just to clarify, if you combine this with the nullable types syntax > (assuming prefix), then the nullable applies to the entire union type: > > ?int|float === int | float | null > > I do find the shorter syntax confusing TBH. > > Which actually leads me to a different thought: defining custom types and > using them instead. > > I very much like Hacks type/newtype stuff, if we extended that to support > union types: > > newtype Numeric = int|float; > > Then you end up with simply: ?Numeric as your type (it should be > namespaced). > > You could further expand that with casting rules: > > newtype Numeric = int|float { > string as float; > bool as int; > } > > or even go so far as: > > newtype Numeric = function($value): int|float { > if ($value typeof int) { > return $value; > } > > return (float) $value; > } > > FTR: I hate that last one, just spitballing. > > - Davey > > P.S. > if someone is willing to tackle the code for custom types I'm willing to > write an RFC This issue is addressed partially in the future scope section of the RFC: https://wiki.php.net/rfc/union_types#long_type_expressions. If both nullable and full union types are allowed I was planning on disallowing the short-hand notation when using unions. As it isn't that relevant at this stage it isn't noted in the RFCs anywhere.