Topic: Adding library support for recursive lambdas


Author: yegor.derevenets@gmail.com
Date: Wed, 30 Sep 2015 11:05:26 -0700 (PDT)
Raw View
------=_Part_492_595625467.1443636326550
Content-Type: multipart/alternative;
 boundary="----=_Part_493_1904243390.1443636326550"

------=_Part_493_1904243390.1443636326550
Content-Type: text/plain; charset=UTF-8

Hi,

it looks like C++14 generic lambdas and Y combinator play really well
together
when you want to write a recursive lambda. So, I wrote a draft proposal to
include Y combinator into the standard:

    http://derevenets.com/public/yc-proposal.html

Could you have a look and evaluate the idea?

--
Yegor Derevenets

--

---
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_493_1904243390.1443636326550
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>it looks like C++14 generic lambdas and Y combi=
nator play really well together<br>when you want to write a recursive lambd=
a. So, I wrote a draft proposal to<br>include Y combinator into the standar=
d:<br><br>=C2=A0=C2=A0=C2=A0 http://derevenets.com/public/yc-proposal.html<=
br><br>Could you have a look and evaluate the idea?<br><br>--<br>Yegor Dere=
venets<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&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 />

------=_Part_493_1904243390.1443636326550--
------=_Part_492_595625467.1443636326550--

.


Author: Richard Smith <richard@metafoo.co.uk>
Date: Wed, 30 Sep 2015 11:26:37 -0700
Raw View
--001a11438a8e2e070e0520fb1241
Content-Type: text/plain; charset=UTF-8

On Wed, Sep 30, 2015 at 11:05 AM, <yegor.derevenets@gmail.com> wrote:

> Hi,
>
> it looks like C++14 generic lambdas and Y combinator play really well
> together
> when you want to write a recursive lambda. So, I wrote a draft proposal to
> include Y combinator into the standard:
>
>     http://derevenets.com/public/yc-proposal.html
>
> Could you have a look and evaluate the idea?
>

I think this would be better as a first-class language feature. I ran out
of time for the pre-Kona meeting, but I was intending on writing a paper to
allow giving a lambda a name (scoped to its own body):

  auto x = []fib(int a) { return a > 1 ? fib(a - 1) + fib(a - 2) : a; };

Here, 'fib' is the equivalent of the lambda's *this (with some annoying
special rules to allow this to work despite the lambda's closure type being
incomplete).

--

---
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/.

--001a11438a8e2e070e0520fb1241
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 W=
ed, Sep 30, 2015 at 11:05 AM,  <span dir=3D"ltr">&lt;<a href=3D"mailto:yego=
r.derevenets@gmail.com" target=3D"_blank">yegor.derevenets@gmail.com</a>&gt=
;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
..8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hi,<br><=
br>it looks like C++14 generic lambdas and Y combinator play really well to=
gether<br>when you want to write a recursive lambda. So, I wrote a draft pr=
oposal to<br>include Y combinator into the standard:<br><br>=C2=A0=C2=A0=C2=
=A0 <a href=3D"http://derevenets.com/public/yc-proposal.html" target=3D"_bl=
ank">http://derevenets.com/public/yc-proposal.html</a><br><br>Could you hav=
e a look and evaluate the idea?</div></blockquote><div><br></div><div>I thi=
nk this would be better as a first-class language feature. I ran out of tim=
e for the pre-Kona meeting, but I was intending on writing a paper to allow=
 giving a lambda a name (scoped to its own body):</div><div><br></div><div>=
=C2=A0 auto x =3D []fib(int a) { return a &gt; 1 ? fib(a - 1) + fib(a - 2) =
: a; };</div><div><br></div><div>Here, &#39;fib&#39; is the equivalent of t=
he lambda&#39;s *this (with some annoying special rules to allow this to wo=
rk despite the lambda&#39;s closure type being incomplete).</div></div></di=
v></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 />

--001a11438a8e2e070e0520fb1241--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 30 Sep 2015 11:35:37 -0700 (PDT)
Raw View
------=_Part_693_1424448224.1443638138010
Content-Type: multipart/alternative;
 boundary="----=_Part_694_758126977.1443638138010"

------=_Part_694_758126977.1443638138010
Content-Type: text/plain; charset=UTF-8

In the Design Decisions section, it claims that `y_wrapper` would have the
ability to store a value or reference, depending on a template parameter.
By default it stores a value, but if you construct one yourself, it can
store a reference.

That doesn't seem feasible, not in the intended use case. Remember that
lambda functions have a name, but they are untypeable. Calling `std::y` (a
terrible function name, BTW) uses template argument deduction to figure out
what the lambda's type is. But there's no such thing as template argument
deduction when instantiating a template class like `y_wrapper`. So... how
do you do this:

auto fib = y_wrapper<???, use_reference>([]...);

What goes in the ??? part?

--

---
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_694_758126977.1443638138010
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">In the Design Decisions section, it claims that `y_wrapper=
` would have the ability to store a value or reference, depending on a temp=
late parameter. By default it stores a value, but if you construct one your=
self, it can store a reference.<br><br>That doesn&#39;t seem feasible, not =
in the intended use case. Remember that lambda functions have a name, but t=
hey are untypeable. Calling `std::y` (a terrible function name, BTW) uses t=
emplate argument deduction to figure out what the lambda&#39;s type is. But=
 there&#39;s no such thing as template argument deduction when instantiatin=
g a template class like `y_wrapper`. So... how do you do this:<br><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-wr=
ap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> fib </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> y_wrapper</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;???,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> use_reference</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;([]...);</span></div></code><=
/div><br>What goes in the ??? part?<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&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 />

------=_Part_694_758126977.1443638138010--
------=_Part_693_1424448224.1443638138010--

.


Author: Yegor Derevenets <yegor.derevenets@gmail.com>
Date: Wed, 30 Sep 2015 20:56:28 +0200
Raw View
On Wed, Sep 30, 2015 at 11:35:37AM -0700, Nicol Bolas wrote:
> By default it stores a value, but if you construct one yourself, it can
> store a reference.
>
> That doesn't seem feasible, not in the intended use case.

I meant something like this:

    auto almost_fib = [](auto fib, int x) -> int {
        return x <= 1 ? x : fib(x - 1) + fib(x - 2);
    };

    auto fib = std::y_wrapper<decltype(almost_fib) &>(almost_fib);
    std::cout << fib(42) << std::endl;

Perhaps, I should add this example to the paper.

Naming is not an important issue for now. std::y is good enough for the
start, we can always pick a better name later, once we agree we need
this function in the library.

--
Yegor Derevenets

--

---
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/.

.