220 21618 <CAOfiQqm8eRMpb_6_wsHfraksF8Kato2Ezgdo3ZZFSPh6NXfnTg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Richard Smith <richard@metafoo.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: is await an extension of the do-notation? (was Re:
 Re: Resumable expressions p0114r0 vs async/await P0057R0)
Date: Mon, 12 Oct 2015 12:59:26 -0700
Lines: 169
Approved: news@gmane.org
Message-ID: <CAOfiQqm8eRMpb_6_wsHfraksF8Kato2Ezgdo3ZZFSPh6NXfnTg@mail.gmail.com>
References: <639f0012-8cb4-4db3-82a6-8d042a3497f9@isocpp.org>
	<401aa118-ed0b-4c7b-92cf-3fbd706eff9d@isocpp.org>
	<fcbcc1c4-535c-4fa2-a17d-4acffe84a4b5@isocpp.org>
	<1d15dbc4-e0c1-4df1-86db-014e11f14d26@isocpp.org>
	<56114953.4030701@wanadoo.fr>
	<561B403D.4030403@gmail.com>
	<CAOfiQqkKvZfVatJ1Bz4qSvGc-g6iep0xeP1B1=J1-gCu43NXxg@mail.gmail.com>
	<561C07D1.3080304@gmail.com>
	<e15de7d0-d1b2-48f2-9c43-b32732ca498d@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a114391283726880521edc412
X-Trace: ger.gmane.org 1444679978 10261 80.91.229.3 (12 Oct 2015 19:59:38 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 12 Oct 2015 19:59:38 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDVNBJG4YAIBBHVC6CYAKGQECLWL35Y@isocpp.org Mon Oct 12 21:59:36 2015
Return-path: <std-proposals+bncBDVNBJG4YAIBBHVC6CYAKGQECLWL35Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f199.google.com ([209.85.223.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDVNBJG4YAIBBHVC6CYAKGQECLWL35Y@isocpp.org>)
	id 1ZljFp-00015X-Bu
	for gclcip-std-proposals@m.gmane.org; Mon, 12 Oct 2015 21:59:29 +0200
Original-Received: by ioae62 with SMTP id e62sf40447432ioa.2
        for <gclcip-std-proposals@m.gmane.org>; Mon, 12 Oct 2015 12:59:28 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from:to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=F9nIUez7wVo4jT/9VlGlQ38LxBwUFch8dxbkAFjN8ac=;
        b=E9CdqzyTc/kfL8JaOA8NwsZc8pNJd+6zTg5hhQb/NHY9Nu19LGOjXeFimr3oeRVBFK
         jxBWBY3eUMaIBhKgvjFVJn76r5MitjmYN+unG2Ma6J+WxckyHdiVBW7bwshHH9iNZiqp
         N1JysK0dO2Nf5DPUcp+bLuwABi/ilgGsKcRbGwszaEPQeh19/TMWR1Yk/rMEcKZJ6zZy
         NSZ4zXHZj+y5tdVZZOzq02zfsC8wYnTtExP2LnU55BAqbVqt65cX34Nk+jnGgMhMRyub
         zE690HA3ku0nobWYXzq0iEMH8DfgntsWdKzUBbhJ3lKXxuF+/PcwqzXG87Y+Qf+UzWJ+
         +HzA==
X-Gm-Message-State: ALoCoQmpSGkmtV+1ZXXcjT+qnagp0JKMpVoQ0KaEA1XLRVj5okTVT3U3t0HC/VgP3/Tyy47tYkPZ
X-Received: by 10.182.215.226 with SMTP id ol2mr25925829obc.11.1444679968653;
        Mon, 12 Oct 2015 12:59:28 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.23.42 with SMTP id 39ls2682053qgo.70.gmail; Mon, 12 Oct
 2015 12:59:26 -0700 (PDT)
X-Received: by 10.31.194.2 with SMTP id s2mr17862215vkf.39.1444679966694;
        Mon, 12 Oct 2015 12:59:26 -0700 (PDT)
Original-Received: from mail-vk0-x22b.google.com (mail-vk0-x22b.google.com. [2607:f8b0:400c:c05::22b])
        by mx.google.com with ESMTPS id f40si1787127vki.4.2015.10.12.12.59.26
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 12 Oct 2015 12:59:26 -0700 (PDT)
Received-SPF: pass (google.com: domain of metafoo@gmail.com designates 2607:f8b0:400c:c05::22b as permitted sender) client-ip=2607:f8b0:400c:c05::22b;
Original-Received: by vkgc187 with SMTP id c187so28541475vkg.3
        for <std-proposals@isocpp.org>; Mon, 12 Oct 2015 12:59:26 -0700 (PDT)
X-Received: by 10.31.54.83 with SMTP id d80mr19153685vka.88.1444679966464;
 Mon, 12 Oct 2015 12:59:26 -0700 (PDT)
Original-Sender: metafoo@gmail.com
Original-Received: by 10.31.142.72 with HTTP; Mon, 12 Oct 2015 12:59:26 -0700 (PDT)
In-Reply-To: <e15de7d0-d1b2-48f2-9c43-b32732ca498d@isocpp.org>
X-Original-Sender: richard@metafoo.co.uk
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of metafoo@gmail.com designates 2607:f8b0:400c:c05::22b as permitted
 sender) smtp.mailfrom=metafoo@gmail.com;       dkim=pass header.i=@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:21618
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21618>

--001a114391283726880521edc412
Content-Type: text/plain; charset=UTF-8

On Mon, Oct 12, 2015 at 12:30 PM, Gor Nishanov <gornishanov@gmail.com>
wrote:

> Evgeny:
>
> Note the "purity" word in Richard's answer.
> If you write a body of the coroutine in a pure manner, you can hack P0057
> and in your await_suspend for the list monad resume the coroutine multiple
> times.
> You need to provide proper final_suspend and return_value to make it work.
> But it will work ONLY if your body is pure :-). That is the body of your
> coroutine. And you cannot save any state in the awaiter, since it is torn
> down at the end of the full expressions, hence, I am using thread_local to
> ferry a value from await_suspend to await_resume.
>
> Here is "do not try this at home" awaiter for the list<T>. Untested. Just
> an idea of how it can look like.
>
> auto operator await(list<T> const& l) {
>   struct awaiter {
>     list<T> const * list_;
>
>     static thread_local T* result_;
>
>     bool await_ready() { return false; }
>
>     void await_suspend(coroutine_handle<> h) {
>        auto l = list_;
>        for (auto && item : *l) { result_ = &item; h.resume(); }
>

For this to work, I think you'd need your coroutine to (somehow) repeatedly
await the list item. That is, instead of:

list_monad<int> foo(list_monad<int> v) {
  int x = await v;
  return x * x;
}

.... you'd need to write:

list_monad<int> foo(list_monad<int> v) {
loop:
  int x = await v;
  // somehow return x * x then conditionally goto loop.
}

.... because you don't have any kind of call/cc primitive.

-- 

--- 
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/.

--001a114391283726880521edc412
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On M=
on, Oct 12, 2015 at 12:30 PM, Gor Nishanov <span dir=3D"ltr">&lt;<a href=3D=
"mailto:gornishanov@gmail.com" target=3D"_blank">gornishanov@gmail.com</a>&=
gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px =
0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);bord=
er-left-style:solid;padding-left:1ex"><div dir=3D"ltr">Evgeny:<div><br></di=
v><div>Note the &quot;purity&quot; word in Richard&#39;s answer.</div><div>=
If you write a body of the coroutine in a pure manner, you can hack P0057 a=
nd in your await_suspend for the list monad resume the coroutine multiple t=
imes.</div><div>You need to provide proper final_suspend and return_value t=
o make it work. But it will work ONLY if your body is pure :-). That is the=
 body of your coroutine. And you cannot save any state in the awaiter, sinc=
e it is torn down at the end of the full expressions, hence, I am using thr=
ead_local to ferry a value from await_suspend to await_resume.</div><div><b=
r></div><div>Here is &quot;do not try this at home&quot; awaiter for the li=
st&lt;T&gt;. Untested. Just an idea of how it can look like.</div><div><br>=
</div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-=
word;background-color:rgb(250,250,250)"><code><div><span style=3D"color:rgb=
(0,0,136)">auto</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(0,0,136)">operator</span><span style=3D"color:rgb(0,0,0)"> aw=
ait</span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color=
:rgb(0,0,0)">list</span><span style=3D"color:rgb(102,102,0)">&lt;</span><sp=
an style=3D"color:rgb(0,0,0)">T</span><span style=3D"color:rgb(102,102,0)">=
&gt;</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rg=
b(0,0,136)">const</span><span style=3D"color:rgb(102,102,0)">&amp;</span><s=
pan style=3D"color:rgb(0,0,0)"> l</span><span style=3D"color:rgb(102,102,0)=
">)</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb=
(102,102,0)">{</span><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 </span><sp=
an style=3D"color:rgb(0,0,136)">struct</span><span style=3D"color:rgb(0,0,0=
)"> awaiter </span><span style=3D"color:rgb(102,102,0)">{</span><span style=
=3D"color:rgb(0,0,0)"> <br>=C2=A0 =C2=A0 list</span><span style=3D"color:rg=
b(102,102,0)">&lt;</span><span style=3D"color:rgb(0,0,0)">T</span><span sty=
le=3D"color:rgb(102,102,0)">&gt;</span><span style=3D"color:rgb(0,0,0)"> </=
span><span style=3D"color:rgb(0,0,136)">const</span><span style=3D"color:rg=
b(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">*</span><span style=
=3D"color:rgb(0,0,0)"> list_</span><span style=3D"color:rgb(102,102,0)">;</=
span><span style=3D"color:rgb(0,0,0)"> <br><br>=C2=A0 =C2=A0 </span><span s=
tyle=3D"color:rgb(0,0,136)">static</span><span style=3D"color:rgb(0,0,0)"> =
thread_local T</span><span style=3D"color:rgb(102,102,0)">*</span><span sty=
le=3D"color:rgb(0,0,0)"> result_</span><span style=3D"color:rgb(102,102,0)"=
>;</span><span style=3D"color:rgb(0,0,0)"> <br><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color:rgb(0,0,136)">bool</span><span style=3D"color:rgb(0,0,0)"=
> await_ready</span><span style=3D"color:rgb(102,102,0)">()</span><span sty=
le=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</spa=
n><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136=
)">return</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"col=
or:rgb(0,0,136)">false</span><span style=3D"color:rgb(102,102,0)">;</span><=
span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)=
">}</span><span style=3D"color:rgb(0,0,0)"> <br><br>=C2=A0 =C2=A0 </span><s=
pan style=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0,0)=
"> await_suspend</span><span style=3D"color:rgb(102,102,0)">(</span><span s=
tyle=3D"color:rgb(0,0,0)">coroutine_handle</span><span style=3D"color:rgb(1=
02,102,0)">&lt;&gt;</span><span style=3D"color:rgb(0,0,0)"> h</span><span s=
tyle=3D"color:rgb(102,102,0)">)</span><span style=3D"color:rgb(0,0,0)"> </s=
pan><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rgb(0=
,0,0)"> <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,=
136)">auto</span><span style=3D"color:rgb(0,0,0)"> l </span><span style=3D"=
color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> list_</sp=
an><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,=
0,0)"> <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,1=
36)">for</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"colo=
r:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,136)">auto</span><sp=
an style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=
&amp;&amp;</span><span style=3D"color:rgb(0,0,0)"> item </span><span style=
=3D"color:rgb(102,102,0)">:</span><span style=3D"color:rgb(0,0,0)"> </span>=
<span style=3D"color:rgb(102,102,0)">*</span><span style=3D"color:rgb(0,0,0=
)">l</span><span style=3D"color:rgb(102,102,0)">)</span><span style=3D"colo=
r:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">{</span><span st=
yle=3D"color:rgb(0,0,0)"> result_ </span><span style=3D"color:rgb(102,102,0=
)">=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:=
rgb(102,102,0)">&amp;</span><span style=3D"color:rgb(0,0,0)">item</span><sp=
an style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)">=
 h</span><span style=3D"color:rgb(102,102,0)">.</span><span style=3D"color:=
rgb(0,0,0)">resume</span><span style=3D"color:rgb(102,102,0)">();</span><sp=
an style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=
}</span><span style=3D"color:rgb(0,0,0)"> <br></span></div></code></div></d=
iv></div></blockquote><div><br></div><div>For this to work, I think you&#39=
;d need your coroutine to (somehow) repeatedly await the list item. That is=
, instead of:</div><div><br></div><div>list_monad&lt;int&gt; foo(list_monad=
&lt;int&gt; v) {</div><div>=C2=A0 int x =3D await v;</div><div>=C2=A0 retur=
n x * x;</div><div>}</div><div><br></div><div>... you&#39;d need to write:<=
/div><div><br></div><div><div>list_monad&lt;int&gt; foo(list_monad&lt;int&g=
t; v) {</div><div>loop:</div><div>=C2=A0 int x =3D await v;</div><div>=C2=
=A0 // somehow return x * x then conditionally goto loop.</div><div>}</div>=
</div><div><br></div><div>... because you don&#39;t have any kind of call/c=
c primitive.</div></div></div></div>

<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 />

--001a114391283726880521edc412--

.
