Topic: operator try (was Proposal: Monadic operations


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Tue, 3 Oct 2017 23:32:38 +0200
Raw View
This is a multi-part message in MIME format.
--------------88256223DC73035A1E133639
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 03/10/2017 =C3=A0 18:23, 'Jeffrey Yasskin' via ISO C++ Standard - Future=
=20
Proposals a =C3=A9crit=C2=A0:
> FWIW, I'd be more interested in a proposal to help std::optional take=20
> advantage of the monadic properties of the coroutines language feature.

I believe this is orthogonal. We can have a monadic interface and a more=20
user oriented interface close to co_await.

While we can define operator co_await for optional, expected and=20
result<T>, these types share something in common. They are some kind of=20
SuccessOrError and have the possibility to know if there is one of them=20
and to extract the Success value or the Failure Value.

 =C2=A0=C2=A0=C2=A0 auto v =3D try opt_expr;

to be translated in a much simpler and more efficient way.

In addition using co_await on a type that doesn't suspend is not natural=20
to some of us.

Niall has started a draft paper that we are polishing.=C2=A0 This operator=
=20
try would be customized in a similar but simpler way to co_await.

I've also a draft of SuccessOrError that I would like to finish for=20
Albuquerque
https://github.com/viboes/std-make/blob/master/doc/proposal/nullable/Valued=
OrError.md

Here it is an example:

U h(T);

X<T,E> f();

X<U,E> g() {
 =C2=A0=C2=A0=C2=A0 auto t =3D=C2=A0 try f();
 =C2=A0=C2=A0=C2=A0 return h(t);
}

The meaning of a try-expression is given by the following transformation

X<U,E> g() {
 =C2=A0=C2=A0=C2=A0 auto __trier =3D operator try(f());
 =C2=A0=C2=A0=C2=A0 if ( __trier.failed() )
 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return __trier.failure_value();
 =C2=A0=C2=A0=C2=A0 auto t =3D __trier.success_value();
 =C2=A0=C2=A0=C2=A0 return h(t);
}


Any feedback on this papers is welcome.

Vicente

P.S. I'll contact Nial to see if he can share his paper already.

>

--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/49346690-6184-690b-bba5-0c2c0db4b8f0%40wanadoo.f=
r.

--------------88256223DC73035A1E133639
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 text=3D"#000000" bgcolor=3D"#FFFFFF">
    <div class=3D"moz-cite-prefix">Le 03/10/2017 =C3=A0 18:23, 'Jeffrey
      Yasskin' via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<=
br>
    </div>
    <blockquote type=3D"cite"
cite=3D"mid:CANh-dXmzW7bJBRcXbevtVsUwAsMidpLnuyEyOtnyNSByFWK36Q@mail.gmail.=
com">
      <div dir=3D"ltr">FWIW, I'd be more interested in a proposal to help
        std::optional take advantage of the monadic properties of the
        coroutines language feature.</div>
    </blockquote>
    <br>
    I believe this is orthogonal. We can have a monadic interface and a
    more user oriented interface close to co_await.<br>
    <br>
    While we can define operator co_await for optional, expected and
    result&lt;T&gt;, these types share something in common. They are
    some kind of SuccessOrError and have the possibility to know if
    there is one of them and to extract the Success value or the Failure
    Value.<br>
    <br>
    =C2=A0=C2=A0=C2=A0 auto v =3D try opt_expr;<br>
    =C2=A0=C2=A0=C2=A0 <br>
    to be translated in a much simpler and more efficient way.<br>
    <br>
    In addition using co_await on a type that doesn't suspend is not
    natural to some of us.<br>
    <br>
    Niall has started a draft paper that we are polishing.=C2=A0 This
    operator try would be customized in a similar but simpler way to
    co_await.<br>
    <br>
    I've also a draft of SuccessOrError that I would like to finish for
    Albuquerque<br>
    =C2=A0=C2=A0=C2=A0
<a class=3D"moz-txt-link-freetext" href=3D"https://github.com/viboes/std-ma=
ke/blob/master/doc/proposal/nullable/ValuedOrError.md">https://github.com/v=
iboes/std-make/blob/master/doc/proposal/nullable/ValuedOrError.md</a><br>
    <br>
    Here it is an example:<br>
    <br>
    U h(T);<br>
    <br>
    X&lt;T,E&gt; f();<br>
    <br>
    X&lt;U,E&gt; g() {<br>
    =C2=A0=C2=A0=C2=A0 auto t =3D=C2=A0 try f();<br>
    =C2=A0=C2=A0=C2=A0 return h(t);=C2=A0 <br>
    }=C2=A0 <br>
    <br>
    The meaning of a try-expression is given by the following
    transformation<br>
    <br>
    X&lt;U,E&gt; g() {<br>
    =C2=A0=C2=A0=C2=A0 auto __trier =3D operator try(f());<br>
    =C2=A0=C2=A0=C2=A0 if ( __trier.failed() )<br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return __trier.failure_value=
();<br>
    =C2=A0=C2=A0=C2=A0 auto t =3D __trier.success_value();=C2=A0=C2=A0=C2=
=A0 <br>
    =C2=A0=C2=A0=C2=A0 return h(t);=C2=A0 <br>
    }=C2=A0 <br>
    <br>
    <br>
    Any feedback on this papers is welcome.<br>
    <br>
    Vicente<br>
    <br>
    P.S. I'll contact Nial to see if he can share his paper already.<br>
    <br>
    <blockquote type=3D"cite"
cite=3D"mid:CANh-dXmzW7bJBRcXbevtVsUwAsMidpLnuyEyOtnyNSByFWK36Q@mail.gmail.=
com">
      <div class=3D"gmail_extra"><br>
      </div>
    </blockquote>
    <br>
  </body>
</html>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/49346690-6184-690b-bba5-0c2c0db4b8f0%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/49346690-6184-690b-bba5-0c2c0db4b8f0=
%40wanadoo.fr</a>.<br />

--------------88256223DC73035A1E133639--

.