Topic: Sum types visitation and future continuation similarities


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Mon, 18 May 2015 21:04:36 +0200
Raw View
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--

.