<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: Multiple error handling with the optional monad in C++	</title>
	<atom:link href="https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Sun, 19 Nov 2017 13:34:34 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.3</generator>
	<item>
		<title>
		By: Michael Entin		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-628</link>

		<dc:creator><![CDATA[Michael Entin]]></dc:creator>
		<pubDate>Fri, 03 Nov 2017 07:22:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-628</guid>

					<description><![CDATA[I would say the end result is horrible, same nested functions - lacking the benefits of Haskell, where you simply compose functions.

It is pretty trivial to make a better version, where you could simply compose functions without ugly syntax. You just need to use (1) left associative operator (i.e. &#062;&#062; rather than &#062;&#062;=, &#062;&#062;= is left-associative in Haskell but not in C++), (2) use Currying. The end result might look like this (it compiles and works, but probably can be improved):

optional f1(int a);
optional f2(std::pair bc);
optional f3(int d);
optional f4(int e);

// and here is how simple the actual function composition looks like:
auto x = f1(3) &#062;&#062; add_arg(f1(4)) &#062;&#062; f2 &#062;&#062; f3 &#062;&#062; f4;]]></description>
			<content:encoded><![CDATA[<p>I would say the end result is horrible, same nested functions &#8211; lacking the benefits of Haskell, where you simply compose functions.</p>
<p>It is pretty trivial to make a better version, where you could simply compose functions without ugly syntax. You just need to use (1) left associative operator (i.e. &gt;&gt; rather than &gt;&gt;=, &gt;&gt;= is left-associative in Haskell but not in C++), (2) use Currying. The end result might look like this (it compiles and works, but probably can be improved):</p>
<p>optional f1(int a);<br />
optional f2(std::pair bc);<br />
optional f3(int d);<br />
optional f4(int e);</p>
<p>// and here is how simple the actual function composition looks like:<br />
auto x = f1(3) &gt;&gt; add_arg(f1(4)) &gt;&gt; f2 &gt;&gt; f3 &gt;&gt; f4;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-491</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Wed, 16 Aug 2017 17:09:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-491</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-486&quot;&gt;Dmitry Pinaev&lt;/a&gt;.

In fact I&#039;ve split in into two steps, I first show the implementation, then the prototype. I made that choice because each of them needs focus to understand, and I put the implementation first because it seems more natural to grasp to me.
Anyway, thanks for pointing this out, here is the complete implementation:
&lt;pre&gt;&lt;code&gt;

template
auto operator&#062;&#062;=(boost::optional const&#038; t, TtoOptionalU f) -&#062; decltype(f(*t))
{
    if (t)
    {
        return f(*t);
    }
    else
    {
        return boost::none;
    }
}
&lt;/code&gt;&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-486">Dmitry Pinaev</a>.</p>
<p>In fact I&#8217;ve split in into two steps, I first show the implementation, then the prototype. I made that choice because each of them needs focus to understand, and I put the implementation first because it seems more natural to grasp to me.<br />
Anyway, thanks for pointing this out, here is the complete implementation:</p>
<pre><code>

template
auto operator&gt;&gt;=(boost::optional const&amp; t, TtoOptionalU f) -&gt; decltype(f(*t))
{
    if (t)
    {
        return f(*t);
    }
    else
    {
        return boost::none;
    }
}
</code></pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Dmitry Pinaev		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-486</link>

		<dc:creator><![CDATA[Dmitry Pinaev]]></dc:creator>
		<pubDate>Sat, 12 Aug 2017 22:13:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-486</guid>

					<description><![CDATA[Maybe I should have read this post another two times but... did you intentionally omit the implementation of your operator&#062;&#062;= ?]]></description>
			<content:encoded><![CDATA[<p>Maybe I should have read this post another two times but&#8230; did you intentionally omit the implementation of your operator&gt;&gt;= ?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: amccartney		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-410</link>

		<dc:creator><![CDATA[amccartney]]></dc:creator>
		<pubDate>Sat, 15 Jul 2017 01:23:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-410</guid>

					<description><![CDATA[The &#062;&#062;= is right-to-left associative in C++. That might lead to surprising results when chaining binds together]]></description>
			<content:encoded><![CDATA[<p>The &gt;&gt;= is right-to-left associative in C++. That might lead to surprising results when chaining binds together</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jeremiah O'Neil		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-402</link>

		<dc:creator><![CDATA[Jeremiah O'Neil]]></dc:creator>
		<pubDate>Thu, 13 Jul 2017 16:46:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-402</guid>

					<description><![CDATA[I just learned that short-circuiting and left-to-right evaluation order are guaranteed for non-overloaded &#038;&#038; (C++ standard 1.9.18)! So, we can simply write:
&lt;pre&gt;&lt;code class=&quot;c++&quot;&gt;
if (optional x, y;
    (x = f(3)) &#038;&#038; (y = f(4)) &#038;&#038; (x = g(*x, *y)) &#038;&#038; (x = h(*x)) &#038;&#038; (x = h(*x)))
{
   // we can use *x 
} 
else 
{
   // we know that something went wrong 
}
&lt;/code&gt;&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>I just learned that short-circuiting and left-to-right evaluation order are guaranteed for non-overloaded &amp;&amp; (C++ standard 1.9.18)! So, we can simply write:</p>
<pre><code class="c++">
if (optional x, y;
    (x = f(3)) &amp;&amp; (y = f(4)) &amp;&amp; (x = g(*x, *y)) &amp;&amp; (x = h(*x)) &amp;&amp; (x = h(*x)))
{
   // we can use *x 
} 
else 
{
   // we know that something went wrong 
}
</code></pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jeremiah O'Neil		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-397</link>

		<dc:creator><![CDATA[Jeremiah O'Neil]]></dc:creator>
		<pubDate>Tue, 11 Jul 2017 18:53:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-397</guid>

					<description><![CDATA[Good post! It starts practical and gets interesting. On the practical side of things, I think the naive composition of optionals is just fine when there are only a few errors one may run into; it&#039;s not hard to write or read and it&#039;s easy to add specific error handling logic or logging to it. Plus, with the new if statement initializers you can write it more concisely and without bleeding any temporary variables:

&lt;pre&gt;&lt;code class=&quot;c++&quot;&gt;
optional result;

if (auto b = f(3), c = f(4); b &#038;&#038; c)
{
    if (auto d = g(*b, *c); d)
    {
        if (auto e = h(*d); e)
        {
            result = h(*e);
               }
    }
}
&lt;/code&gt;&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Good post! It starts practical and gets interesting. On the practical side of things, I think the naive composition of optionals is just fine when there are only a few errors one may run into; it&#8217;s not hard to write or read and it&#8217;s easy to add specific error handling logic or logging to it. Plus, with the new if statement initializers you can write it more concisely and without bleeding any temporary variables:</p>
<pre><code class="c++">
optional result;

if (auto b = f(3), c = f(4); b &amp;&amp; c)
{
    if (auto d = g(*b, *c); d)
    {
        if (auto e = h(*d); e)
        {
            result = h(*e);
               }
    }
}
</code></pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adi Shavit		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-394</link>

		<dc:creator><![CDATA[Adi Shavit]]></dc:creator>
		<pubDate>Tue, 11 Jul 2017 11:50:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-394</guid>

					<description><![CDATA[In the C-like example, another problem, is that you are always calling all the functions even when an error is reported, thus wasting effort or worst, passing garbage to the functions.

[*typo: &quot;wildly&quot; =&#062; &quot;widely&quot;]]]></description>
			<content:encoded><![CDATA[<p>In the C-like example, another problem, is that you are always calling all the functions even when an error is reported, thus wasting effort or worst, passing garbage to the functions.</p>
<p>[*typo: &#8220;wildly&#8221; =&gt; &#8220;widely&#8221;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Cristian Pallarés		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-391</link>

		<dc:creator><![CDATA[Cristian Pallarés]]></dc:creator>
		<pubDate>Sat, 08 Jul 2017 15:58:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-391</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-388&quot;&gt;Sarfaraz Nawaz&lt;/a&gt;.

You are totally right <img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f44d.png" alt="👍" class="wp-smiley" style="height: 1em; max-height: 1em;" />]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-388">Sarfaraz Nawaz</a>.</p>
<p>You are totally right 👍</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Sarfaraz Nawaz		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-388</link>

		<dc:creator><![CDATA[Sarfaraz Nawaz]]></dc:creator>
		<pubDate>Fri, 07 Jul 2017 15:28:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-388</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-381&quot;&gt;Cristian Pallarés&lt;/a&gt;.

You dont need the lambdas in the `then()` functions. You can just write: .then(f2).then(f3).then(f4);]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-381">Cristian Pallarés</a>.</p>
<p>You dont need the lambdas in the `then()` functions. You can just write: .then(f2).then(f3).then(f4);</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Cristian Pallarés		</title>
		<link>https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-384</link>

		<dc:creator><![CDATA[Cristian Pallarés]]></dc:creator>
		<pubDate>Wed, 05 Jul 2017 14:15:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=896#comment-384</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-383&quot;&gt;Jonathan Boccara&lt;/a&gt;.

That will require a templated variadic class and a variadic method. Maybe I&#039;ll try to implement it... I don&#039;t have much time these days :(]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/07/04/multiple-error-handling-with-the-optional-monad-in-c/#comment-383">Jonathan Boccara</a>.</p>
<p>That will require a templated variadic class and a variadic method. Maybe I&#8217;ll try to implement it&#8230; I don&#8217;t have much time these days 🙁</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
