220 17944 <555A37C4.4070607@wanadoo.fr> article
Path: news.gmane.org!not-for-mail
From: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Sum types visitation and future continuation similarities
Date: Mon, 18 May 2015 21:04:36 +0200
Lines: 175
Approved: news@gmane.org
Message-ID: <555A37C4.4070607@wanadoo.fr>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------010703090002040307090707"
X-Trace: ger.gmane.org 1431975452 3528 80.91.229.3 (18 May 2015 18:57:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 18 May 2015 18:57:32 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDH67CONY4PBBD7M5CVAKGQEMKMIQMY@isocpp.org Mon May 18 20:57:23 2015
Return-path: <std-proposals+bncBDH67CONY4PBBD7M5CVAKGQEMKMIQMY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f200.google.com ([209.85.212.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDH67CONY4PBBD7M5CVAKGQEMKMIQMY@isocpp.org>)
	id 1YuQE5-0008Dv-BM
	for gclcip-std-proposals@m.gmane.org; Mon, 18 May 2015 20:57:21 +0200
Original-Received: by wivs14 with SMTP id s14sf26667286wiv.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 18 May 2015 11:57:20 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=pT/PRTAi2VJe74dfPxqjZxDzXTtVj9OdDGRmtw/s9tg=;
        b=AXrSstwCUqD/G0EgqhehhtT2wrx8JXIUOWb/1wBaRGgkl/NOXXeIwJQrq/BlCOuTiz
         L3Wv2aIyv2PpfL0KUkMFY8gHSrv65kMMuLsJ/MVvvo7FJupeG7dE6Mn++w6TyMdWfDap
         NCLzkBjziODMEBQz6L7t0D4QnKzdgbR4vfuuHFq4MUUCEE6sixc/8NejJ8sp5y+M333R
         tRR6dB2OJ7x8/mKmtsSSzAFB0b8pq+BI9honyFtdsS7gBOehaljJuI2INaCc8+j9zNMh
         YCM6OAHtj2lvASy2aIw5zj9dGPGM+eNKTkrut2IIqYnLdY4TBjvvA85pq1FWBxD/d/qs
         Ts7A==
X-Gm-Message-State: ALoCoQlXuRTSAWrvkpzwa0lcHjaNX7J6hdzkAnIWGfvTciIn7zQ/uhPkdceoUd92pyn68YO35C75
X-Received: by 10.152.184.73 with SMTP id es9mr18830233lac.4.1431975440730;
        Mon, 18 May 2015 11:57:20 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.7.135 with SMTP id j7ls505567wia.22.canary; Mon, 18 May
 2015 11:57:19 -0700 (PDT)
X-Received: by 10.194.84.100 with SMTP id x4mr17451520wjy.69.1431975439531;
        Mon, 18 May 2015 11:57:19 -0700 (PDT)
Original-Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr. [80.12.242.127])
        by mx.google.com with ESMTPS id ck1si19226865wjc.67.2015.05.18.11.57.19
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Mon, 18 May 2015 11:57:19 -0700 (PDT)
Received-SPF: neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) client-ip=80.12.242.127;
Original-Received: from new-host.home ([92.139.141.131])
	by mwinf5d61 with ME
	id VWxJ1q00X2qJ0z803WxJwf; Mon, 18 May 2015 20:57:19 +0200
X-ME-Helo: new-host.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Mon, 18 May 2015 20:57:19 +0200
X-ME-IP: 92.139.141.131
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
X-Original-Sender: vicente.botet@wanadoo.fr
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 80.12.242.127 is neither permitted nor denied by best guess
 record for domain of vicente.botet@wanadoo.fr) smtp.mail=vicente.botet@wanadoo.fr
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:17944
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17944>

This is a multi-part message in MIME format.
--------------010703090002040307090707
Content-Type: text/plain; charset=UTF-8; format=flowed

Hi,

In one of the variant threads, BS presented this language like example 
of pattern matching on sum types (union, variants)


     int area(variant<Circle,Square> v)
     {
         inspect(v) {    // look at the variant v
         match Circle c:     return pi*square(c.radius());
         match Square s:   return s.height()*s.width();
         }
     }

It easy to extend the inspection/matching to multiple sum types.

A library solution applied to multiple variants could be

inspect(v, b).match(
   [](Circle c, int j )
     {
     },
   [](auto i, autoj )
     {
       // ...
     }
   );

This is quite close to the when_all(f1, f2).then(); expressions. This 
let me think that we could have a match function for futures because a 
future has either a value or an exception_ptr, so a sum type

f.match(

   [](Circle c)
     {
     },
   [](auto)
     {
       // ...
     }
   );


and that when_all would be close to inspect but applied to futures

when_all(a, b).match(
   [](Circle, int j )
     {
     },
   [](auto i, auto j )
     {
       // ...
     }
   );


Just wanted to share this similarity.

Vicente


-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--------------010703090002040307090707
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>

    <meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <font size=3D"+1">Hi,<br>
      <br>
      In one of the variant threads, BS presented this language like
      example of pattern matching on sum types (union, variants)<br>
      <br>
    </font><br>
    =C2=A0=C2=A0=C2=A0 int area(variant&lt;Circle,Square&gt; v)
    <br>
    =C2=A0=C2=A0=C2=A0 {
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 inspect(v) {=C2=A0=C2=A0=C2=
=A0 // look at the variant v
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Circle c:=C2=A0=C2=A0=
=C2=A0=C2=A0 return pi*square(c.radius());
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 match Square s:=C2=A0=C2=A0 =
return s.height()*s.width();
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
    <br>
    =C2=A0=C2=A0=C2=A0 }
    <font size=3D"+1"><br>
      <br>
      It easy to extend the inspection/matching to multiple sum types.<br>
      <br>
      A library solution applied to multiple variants could be<br>
    </font><br>
    <pre style=3D"margin-left: 1.25cm">inspect(v, b).match(
  [](Circle c, int j )
    {
    },
  [](auto i, autoj )
    {
      // ...
    }
  );</pre>
    <font size=3D"+1">This is quite close to the when_all(f1, f2).then();
      expressions. </font>This let me think that we could have a match
    function for futures because a future has either a value or an
    exception_ptr, so a sum type<br>
    <br>
    f.match(<br>
    <pre style=3D"margin-left: 1.25cm">  [](Circle c)
    {
    },
  [](auto)
    {
      // ...
    }
  );</pre>
    <font size=3D"+1"><br>
    </font>and that when_all would be close to inspect but applied to
    futures<br>
    <pre style=3D"margin-left: 1.25cm">when_all(a, b).match(
  [](Circle, int j )
    {
    },
  [](auto i, auto j )
    {
      // ...
    }
  );</pre>
    <br>
    Just wanted to share this similarity.<br>
    <br>
    <font size=3D"+1">Vicente<br>
      <br>
    </font><br>
  </body>
</html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--------------010703090002040307090707--

.
