Topic: resumable functions and monads
Author: stepik-777@mail.ru
Date: Sat, 7 Dec 2013 06:00:52 -0800 (PST)
Raw View
------=_Part_1556_21060063.1386424852951
Content-Type: text/plain; charset=ISO-8859-1
I'm reading this proposal:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3722.pdf
It looks like adding do-notation for monads from Haskell to C++. It focuses
on std::future, but proposes generalization to user defined types.
It is not clear to me how it will be applied to user defined types. Say, I
want to extend it for std::list, will something like this work?
template<typename A>
struct ListMonad : list<A>
{
using list<A>::list; // inherit constructors
// bind (>>=), apply Func to all elements in *this and concatenate
results
template<typename TFunc>
auto then(TFunc&& Func)
{
auto iter = begin();
auto NewList = Func(ListMonad<A>({ *iter }));
for (++iter; iter != end(); ++iter)
NewList.splice(NewList.end(), Func(ListMonad<A>({ *iter })));
return NewList;
}
// get element from unit list
const A& get()
{
if (size() != 1)
throw "";
return *begin();
}
};
// construct unit list
template<typename A>
ListMonad<A> mreturn(A a)
{
return ListMonad<A>({a});
}
ListMonad<int> computeProducts() resumable
{
int a = await ListMonad({1, 2, 3});
int b = await ListMonad({1, 10, 100});
return mreturn(a*b);
}
/* returns list [1, 10, 100, 2, 20, 200, 3, 30, 300], like in Haskell:
computeProducts = do
a <- [1, 2, 3]
b <- [1, 10, 100]
return (a*b)
*/
--
---
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/.
------=_Part_1556_21060063.1386424852951
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I'm reading this proposal: http://www.open-std.org/jtc1/sc=
22/wg21/docs/papers/2013/n3722.pdf<br>It looks like adding do-notation for =
monads from Haskell to C++. It focuses on std::future, but proposes general=
ization to user defined types.<br>It is not clear to me how it will be appl=
ied to user defined types. Say, I want to extend it for std::list, will som=
ething like this work?<br><br><div class=3D"prettyprint" style=3D"backgroun=
d-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style=
: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">template</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">ListMonad</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> list</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">A</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">us=
ing</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> list</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">>::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">list</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">// inherit constructors</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br> </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// bind (>>=3D), apply=
Func to all elements in *this and concatenate results</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">TFunc</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">then</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify=
">TFunc</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Func</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> &nb=
sp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> iter </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">begin</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br> </span><span=
style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">NewList</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Func</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #606;" class=3D"styled-by-prettify">ListM=
onad</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">>({</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">iter </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">}));</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">for</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(++</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">iter</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> iter </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>!=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">end</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">++</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">iter</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> </span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">NewList</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">splice</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">NewList</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">end</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Func</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">ListMonad</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">A</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">>({</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">iter </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">})));</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">NewList</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br> </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br> </span><span style=3D"color: #800;" class=3D"styled=
-by-prettify">// get element from unit list</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> A</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">get</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">if</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">size<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">!=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">throw</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">""</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">return</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">*</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">begin</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><=
span style=3D"color: #800;" class=3D"styled-by-prettify">// construct unit =
list</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">template</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">ListMonad</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">A</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> mreturn</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">A a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">ListMonad</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">A</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">>({</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">a</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">});</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br=
></span><span style=3D"color: #606;" class=3D"styled-by-prettify">ListMonad=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify"><int>=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> computeP=
roducts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> resumable<=
br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>  =
; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> a </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> await </span><span style=3D=
"color: #606;" class=3D"styled-by-prettify">ListMonad</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">({</span><span style=3D"color: #=
066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">});</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> b </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> await </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">ListMonad</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">({</span><span style=3D"color: #066;" class=3D"styl=
ed-by-prettify">1</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">10</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">100</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">});</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> mreturn</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#800;" class=3D"styled-by-prettify">/* returns list [1, 10, 100, 2, 20, 200=
, 3, 30, 300], like in Haskell:<br>computeProducts =3D do<br> =
a <- [1, 2, 3]<br> b <- [1, 10, 100]<br> re=
turn (a*b)<br>*/</span></div></code></div><br><br><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
------=_Part_1556_21060063.1386424852951--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 07 Dec 2013 19:43:56 +0100
Raw View
This is a multi-part message in MIME format.
--------------050000080900030105030007
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 07/12/13 15:00, stepik-777@mail.ru a =E9crit :
> I'm reading this proposal:=20
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3722.pdf
> It looks like adding do-notation for monads from Haskell to C++. It=20
> focuses on std::future, but proposes generalization to user defined types=
..
> It is not clear to me how it will be applied to user defined types.=20
> Say, I want to extend it for std::list, will something like this work?
>
> |
> template<typenameA>
> structListMonad:list<A>
> {
> usinglist<A>::list;// inherit constructors
>
> // bind (>>=3D), apply Func to all elements in *this and concatenate resu=
lts
> template<typenameTFunc>
> autothen(TFunc&&Func)
> {
> autoiter =3Dbegin();
> autoNewList=3DFunc(ListMonad<A>({*iter }));
> for(++iter;iter !=3Dend();++iter)
> NewList.splice(NewList.end(),Func(ListMonad<A>({*iter })));
> returnNewList;
> }
>
> // get element from unit list
> constA&get()
> {
> if(size()!=3D1)
> throw"";
> return*begin();
> }
> };
>
> // construct unit list
> template<typenameA>
> ListMonad<A>mreturn(A a)
> {
> returnListMonad<A>({a});
> }
>
> ListMonad<int>computeProducts()resumable
> {
> inta =3Dawait ListMonad({1,2,3});
> intb =3Dawait ListMonad({1,10,100});
> returnmreturn(a*b);
> }
> /* returns list [1, 10, 100, 2, 20, 200, 3, 30, 300], like in Haskell:
> computeProducts =3D do
> a <- [1, 2, 3]
> b <- [1, 10, 100]
> return (a*b)
> */
> |
>
Hi,
I think you have misunderstood the n3722 proposal. await is only=20
applicable to expressions that return a std::future. The expression
|inta =3Dawait ListMonad({1,2,3});
is incorrect as ||ListMonad({1,2,3})| is not a std::future<int>.
||
You can define monad operations to your list without needing to use await.
What is the continuation function that you want to pass to the bind=20
function to obtain the result you expect?
I don't see any bind function call on the Haskell code. Sorry if this is=20
trivial for some one used to work on Hashkell.
Vicente
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--------------050000080900030105030007
Content-Type: text/html; charset=ISO-8859-1
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">Le 07/12/13 15:00, <a class="moz-txt-link-abbreviated" href="mailto:stepik-777@mail.ru">stepik-777@mail.ru</a> a
écrit :<br>
</div>
<blockquote
cite="mid:bc1ec3e9-46fd-4e57-a852-512c2611714f@isocpp.org"
type="cite">
<div dir="ltr">I'm reading this proposal:
<a class="moz-txt-link-freetext" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3722.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3722.pdf</a><br>
It looks like adding do-notation for monads from Haskell to C++.
It focuses on std::future, but proposes generalization to user
defined types.<br>
It is not clear to me how it will be applied to user defined
types. Say, I want to extend it for std::list, will something
like this work?<br>
<br>
<div class="prettyprint" style="background-color: rgb(250, 250,
250); border-color: rgb(187, 187, 187); border-style: solid;
border-width: 1px; word-wrap: break-word;"><code
class="prettyprint">
<div class="subprettyprint"><span style="color: #008;"
class="styled-by-prettify">template</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #008;" class="styled-by-prettify">typename</span><span
style="color: #000;" class="styled-by-prettify"> A</span><span
style="color: #660;" class="styled-by-prettify">></span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">struct</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">:</span><span
style="color: #000;" class="styled-by-prettify"> list</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #000;" class="styled-by-prettify">A</span><span
style="color: #660;" class="styled-by-prettify">></span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">using</span><span
style="color: #000;" class="styled-by-prettify"> list</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #000;" class="styled-by-prettify">A</span><span
style="color: #660;" class="styled-by-prettify">>::</span><span
style="color: #000;" class="styled-by-prettify">list</span><span
style="color: #660;" class="styled-by-prettify">;</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #800;" class="styled-by-prettify">//
inherit constructors</span><span style="color: #000;"
class="styled-by-prettify"><br>
<br>
</span><span style="color: #800;"
class="styled-by-prettify">// bind (>>=), apply
Func to all elements in *this and concatenate results</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">template</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #008;" class="styled-by-prettify">typename</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">TFunc</span><span
style="color: #660;" class="styled-by-prettify">></span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">auto</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">then</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #606;" class="styled-by-prettify">TFunc</span><span
style="color: #660;" class="styled-by-prettify">&&</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">Func</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">auto</span><span
style="color: #000;" class="styled-by-prettify"> iter </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">begin</span><span
style="color: #660;" class="styled-by-prettify">();</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">auto</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">NewList</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">Func</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #000;" class="styled-by-prettify">A</span><span
style="color: #660;" class="styled-by-prettify">>({</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">*</span><span
style="color: #000;" class="styled-by-prettify">iter </span><span
style="color: #660;" class="styled-by-prettify">}));</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">for</span><span style="color:
#000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">(++</span><span
style="color: #000;" class="styled-by-prettify">iter</span><span
style="color: #660;" class="styled-by-prettify">;</span><span
style="color: #000;" class="styled-by-prettify"> iter </span><span
style="color: #660;" class="styled-by-prettify">!=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">end</span><span
style="color: #660;" class="styled-by-prettify">();</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">++</span><span
style="color: #000;" class="styled-by-prettify">iter</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #606;"
class="styled-by-prettify">NewList</span><span
style="color: #660;" class="styled-by-prettify">.</span><span
style="color: #000;" class="styled-by-prettify">splice</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #606;" class="styled-by-prettify">NewList</span><span
style="color: #660;" class="styled-by-prettify">.</span><span
style="color: #008;" class="styled-by-prettify">end</span><span
style="color: #660;" class="styled-by-prettify">(),</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">Func</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #000;" class="styled-by-prettify">A</span><span
style="color: #660;" class="styled-by-prettify">>({</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">*</span><span
style="color: #000;" class="styled-by-prettify">iter </span><span
style="color: #660;" class="styled-by-prettify">})));</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">return</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">NewList</span><span
style="color: #660;" class="styled-by-prettify">;</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">}</span><span style="color:
#000;" class="styled-by-prettify"><br>
<br>
</span><span style="color: #800;"
class="styled-by-prettify">// get element from unit list</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">const</span><span
style="color: #000;" class="styled-by-prettify"> A</span><span
style="color: #660;" class="styled-by-prettify">&</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #008;" class="styled-by-prettify">get</span><span
style="color: #660;" class="styled-by-prettify">()</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">if</span><span style="color:
#000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #000;" class="styled-by-prettify">size</span><span
style="color: #660;" class="styled-by-prettify">()</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">!=</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">throw</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #080;" class="styled-by-prettify">""</span><span
style="color: #660;" class="styled-by-prettify">;</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">return</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #660;" class="styled-by-prettify">*</span><span
style="color: #008;" class="styled-by-prettify">begin</span><span
style="color: #660;" class="styled-by-prettify">();</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">}</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">};</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #000;"
class="styled-by-prettify"><br>
</span><span style="color: #800;"
class="styled-by-prettify">// construct unit list</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">template</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #008;" class="styled-by-prettify">typename</span><span
style="color: #000;" class="styled-by-prettify"> A</span><span
style="color: #660;" class="styled-by-prettify">></span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #606;"
class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #000;" class="styled-by-prettify">A</span><span
style="color: #660;" class="styled-by-prettify">></span><span
style="color: #000;" class="styled-by-prettify"> mreturn</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #000;" class="styled-by-prettify">A a</span><span
style="color: #660;" class="styled-by-prettify">)</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">return</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify"><</span><span
style="color: #000;" class="styled-by-prettify">A</span><span
style="color: #660;" class="styled-by-prettify">>({</span><span
style="color: #000;" class="styled-by-prettify">a</span><span
style="color: #660;" class="styled-by-prettify">});</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">}</span><span style="color:
#000;" class="styled-by-prettify"><br>
<br>
</span><span style="color: #606;"
class="styled-by-prettify">ListMonad</span><span
style="color: #080;" class="styled-by-prettify"><int></span><span
style="color: #000;" class="styled-by-prettify">
computeProducts</span><span style="color: #660;"
class="styled-by-prettify">()</span><span style="color:
#000;" class="styled-by-prettify"> resumable<br>
</span><span style="color: #660;"
class="styled-by-prettify">{</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">int</span><span style="color:
#000;" class="styled-by-prettify"> a </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> await </span><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify">({</span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">2</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">3</span><span
style="color: #660;" class="styled-by-prettify">});</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">int</span><span style="color:
#000;" class="styled-by-prettify"> b </span><span
style="color: #660;" class="styled-by-prettify">=</span><span
style="color: #000;" class="styled-by-prettify"> await </span><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify">({</span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">10</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">100</span><span
style="color: #660;" class="styled-by-prettify">});</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #008;"
class="styled-by-prettify">return</span><span
style="color: #000;" class="styled-by-prettify"> mreturn</span><span
style="color: #660;" class="styled-by-prettify">(</span><span
style="color: #000;" class="styled-by-prettify">a</span><span
style="color: #660;" class="styled-by-prettify">*</span><span
style="color: #000;" class="styled-by-prettify">b</span><span
style="color: #660;" class="styled-by-prettify">);</span><span
style="color: #000;" class="styled-by-prettify"><br>
</span><span style="color: #660;"
class="styled-by-prettify">}</span><span style="color:
#000;" class="styled-by-prettify"><br>
</span><span style="color: #800;"
class="styled-by-prettify">/* returns list [1, 10, 100,
2, 20, 200, 3, 30, 300], like in Haskell:<br>
computeProducts = do<br>
a <- [1, 2, 3]<br>
b <- [1, 10, 100]<br>
return (a*b)<br>
*/</span></div>
</code></div>
<br>
</div>
</blockquote>
Hi, <br>
<br>
I think you have misunderstood the n3722 proposal. await is only
applicable to expressions that return a std::future. The expression<br>
<br>
<code class="prettyprint"><span style="color: #000;"
class="styled-by-prettify"> </span><span style="color:
#008;" class="styled-by-prettify">int</span><span style="color:
#000;" class="styled-by-prettify"> a </span><span style="color:
#660;" class="styled-by-prettify">=</span><span style="color:
#000;" class="styled-by-prettify"> await </span><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify">({</span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">2</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">3</span><span
style="color: #660;" class="styled-by-prettify">});</span><span
style="color: #000;" class="styled-by-prettify"><br>
<br>
<br>
is incorrect as </span></code><code class="prettyprint"><span
style="color: #606;" class="styled-by-prettify">ListMonad</span><span
style="color: #660;" class="styled-by-prettify">({</span><span
style="color: #066;" class="styled-by-prettify">1</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">2</span><span
style="color: #660;" class="styled-by-prettify">,</span><span
style="color: #000;" class="styled-by-prettify"> </span><span
style="color: #066;" class="styled-by-prettify">3</span><span
style="color: #660;" class="styled-by-prettify">})</span></code>
is not a std::future<int>.<br>
<code class="prettyprint"><span style="color: #000;"
class="styled-by-prettify"></span></code><br>
<br>
You can define monad operations to your list without needing to use
await.<br>
<br>
What is the continuation function that you want to pass to the bind
function to obtain the result you expect?<br>
I don't see any bind function call on the Haskell code. Sorry if
this is trivial for some one used to work on Hashkell.<br>
<br>
Vicente<br>
<br>
</body>
</html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
--------------050000080900030105030007--
.
Author: stepik-777@mail.ru
Date: Sat, 7 Dec 2013 11:25:47 -0800 (PST)
Raw View
------=_Part_1_27197562.1386444347605
Content-Type: text/plain; charset=ISO-8859-1
Yes, I'm talking about very non-trivial things, that may be hard to
understand.
The n3722 proposal says in section 4.1 that await operation can be extended
to types with *then* and *get* member functions. Section 3.2.6 shows how
await is transformed into call to *then*.
So, my code should be transormed into something like this:
ListMonad<int> computeProducts()
{
return ListMonad<int>({ 1, 2, 3 }).then([&](ListMonad<int> a)
{
return ListMonad<int>({ 1, 10, 100 }).then([&](ListMonad<int> b)
{
return mreturn(a.get()*b.get());
});
});
}
For this to work in MSVC it was necessary to add return type to
ListMonad::then (-> decltype(Func(ListMonad<A>({ *begin() }))) )
This looks very similar to the way that do-notation in Haskell generate
calls to *>>=*. Haskell code will be transformed to:
computeProducts = [1, 2, 3] >>= (\a ->
[1, 10, 100] >>= (\b ->
return (a*b)))
--
---
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/.
------=_Part_1_27197562.1386444347605
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Yes, I'm talking about very non-trivial things, that may b=
e hard to understand.<br><br>The n3722 proposal says in section 4.1 that aw=
ait operation can be extended to types with <b>then</b> and <b>get</b> memb=
er functions. Section 3.2.6 shows how await is transformed into call to <b>=
then</b>.<br>So, my code should be transormed into something like this: <br=
><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); =
border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; w=
ord-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #606;" class=3D"styled-by-prettify">ListMonad</=
span><span style=3D"color: #080;" class=3D"styled-by-prettify"><int><=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> computePro=
ducts</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">ListMonad</span><span style=3D"co=
lor: #080;" class=3D"styled-by-prettify"><int></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">({</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">2<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}).</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">then</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">([&](</span><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">ListMonad</span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify"><int></span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">ListMonad</span><span style=3D"color: #080;" class=3D"styled-by-pre=
ttify"><int></span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">({</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #066;" class=3D"styled-by-prettify">10</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">100</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
).</span><span style=3D"color: #008;" class=3D"styled-by-prettify">then</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">([&](</spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">ListMonad</span=
><span style=3D"color: #080;" class=3D"styled-by-prettify"><int></spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> b</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br> &=
nbsp; </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> mreturn</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">get</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">()*</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">b</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">get</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">());</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">});</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">});</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">}</span></div></code></div>For this to work in =
MSVC it was necessary to add return type to ListMonad::then (-> decltype=
(Func(ListMonad<A>({ *begin() }))) )<br><br>This looks very similar t=
o the way that do-notation in Haskell generate calls to <b>>>=3D</b>.=
Haskell code will be transformed to:<br><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
border-style: solid; border-width: 1px; word-wrap: break-word;"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><code><span style=3D"color:=
#800"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>compute=
Products </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span st=
yle=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">2</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">3</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">]</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">>>=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(\</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">a </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">-></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br> &nb=
sp; </span></span></code><code><span style=3D"color:#800"><code><spa=
n style=3D"color:#800"><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">[</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">10</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D=
"styled-by-prettify">100</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">]</span></span></code><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">>>=3D</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(\</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">-></span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br> &=
nbsp; </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span></s=
pan></code><span style=3D"color: #660;" class=3D"styled-by-prettify">))</sp=
an></div></code></div><br><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
------=_Part_1_27197562.1386444347605--
.