<?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/"
		>
<channel>
	<title>Comments on: Monads on the Cheap I: The Maybe Monad</title>
	<atom:link href="http://osteele.com/archives/2007/12/cheap-monads/feed" rel="self" type="application/rss+xml" />
	<link>http://osteele.com/archives/2007/12/cheap-monads</link>
	<description>Languages of the real and artificial.</description>
	<lastBuildDate>Thu, 12 Feb 2009 00:20:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
	<item>
		<title>By: oliver</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-351</link>
		<dc:creator>oliver</dc:creator>
		<pubDate>Tue, 04 Mar 2008 02:30:53 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-351</guid>
		<description>Thanks, John, this is definitely worth noting.

I prefer to place the &#039;var&#039; where the variable is first defined, but this is misleading to anyone coming from Java (or practically any other language), so it&#039;s a real trade off.

(I also prefer to treat variables as read-only except where there loop indices, which somewhat mitigates the problem, at least.)</description>
		<content:encoded><![CDATA[<p>Thanks, John, this is definitely worth noting.</p>
<p>I prefer to place the &#8216;var&#8217; where the variable is first defined, but this is misleading to anyone coming from Java (or practically any other language), so it&#8217;s a real trade off.</p>
<p>(I also prefer to treat variables as read-only except where there loop indices, which somewhat mitigates the problem, at least.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-350</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 04 Mar 2008 02:08:53 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-350</guid>
		<description>Looks like I&#039;m late to the party, but it&#039;s worth noting that in your Javascript examples there is really no &quot;local&quot; scope, only &quot;function scope&quot; so if you write code like your example...

[blockcode]
var product = ...;
if (product) {
  var offering = product.offering;
  if (offering) {
    var merchant = offering.merchant;
    if (merchant) {
      var merchantName = merchant.name;
      if (merchantName)
        displayMerchantName(merchantName);
    }
  }
}

... the in the best case scenario, those &quot;local&quot; variable declarations add variables to the local function&#039;s scope, or in the worst case scenario, if you write this type of code at the top level, those &quot;local&quot; variables will pollute the global namespace.
[blockcode]</description>
		<content:encoded><![CDATA[<p>Looks like I&#8217;m late to the party, but it&#8217;s worth noting that in your Javascript examples there is really no &#8220;local&#8221; scope, only &#8220;function scope&#8221; so if you write code like your example&#8230;</p>
<p>[blockcode]<br />
var product = &#8230;;<br />
if (product) {<br />
  var offering = product.offering;<br />
  if (offering) {<br />
    var merchant = offering.merchant;<br />
    if (merchant) {<br />
      var merchantName = merchant.name;<br />
      if (merchantName)<br />
        displayMerchantName(merchantName);<br />
    }<br />
  }<br />
}</p>
<p>&#8230; the in the best case scenario, those &#8220;local&#8221; variable declarations add variables to the local function&#8217;s scope, or in the worst case scenario, if you write this type of code at the top level, those &#8220;local&#8221; variables will pollute the global namespace.<br />
[blockcode]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: oliver</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-363</link>
		<dc:creator>oliver</dc:creator>
		<pubDate>Tue, 19 Feb 2008 15:25:25 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-363</guid>
		<description>Thanks, Will!

These typos happen to exactly illustrate my point -- that when you add a temporary variable just to get a value from one line to the next, you&#039;ve introduced an error site -- but I won&#039;t pretend that I did this on purpose.  I&#039;ve fixed these (I think) now.</description>
		<content:encoded><![CDATA[<p>Thanks, Will!</p>
<p>These typos happen to exactly illustrate my point &#8212; that when you add a temporary variable just to get a value from one line to the next, you&#8217;ve introduced an error site &#8212; but I won&#8217;t pretend that I did this on purpose.  I&#8217;ve fixed these (I think) now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will Moffat</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-362</link>
		<dc:creator>Will Moffat</dc:creator>
		<pubDate>Tue, 19 Feb 2008 15:02:15 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-362</guid>
		<description>There are minor typos in two of your examples where you define
&#039;var merchantName&#039; but then use &#039;name&#039;
</description>
		<content:encoded><![CDATA[<p>There are minor typos in two of your examples where you define<br />
&#8216;var merchantName&#8217; but then use &#8216;name&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Wolff</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-361</link>
		<dc:creator>Adam Wolff</dc:creator>
		<pubDate>Mon, 31 Dec 2007 21:58:17 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-361</guid>
		<description>Nice post Oliver. I recently saw that Groovy as this feature built in:
http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29

So your example would be:
product.?offering.?merchant.?name

Java&#039;s really the language that needs a better solution for this. I think a lot of Java programmers don&#039;t use null values because it&#039;s so hard to express the intended semantics without building your own type annotations and such. The proposal for Javascript where nullable types are different from non-nullable ones makes a lot of sense to me.</description>
		<content:encoded><![CDATA[<p>Nice post Oliver. I recently saw that Groovy as this feature built in:<br />
<a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29">http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29</a></p>
<p>So your example would be:<br />
product.?offering.?merchant.?name</p>
<p>Java&#8217;s really the language that needs a better solution for this. I think a lot of Java programmers don&#8217;t use null values because it&#8217;s so hard to express the intended semantics without building your own type annotations and such. The proposal for Javascript where nullable types are different from non-nullable ones makes a lot of sense to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aristotle Pagaltzis</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-360</link>
		<dc:creator>Aristotle Pagaltzis</dc:creator>
		<pubDate>Thu, 20 Dec 2007 15:36:46 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-360</guid>
		<description>Hmm, now that I come back to look at it with fresh mind, it occurs to me that I led me &lt;code&gt;reduce&lt;/code&gt; abstraction ad absurdum the moment I used &lt;code&gt;eval&lt;/code&gt; (which, for non-Perl folks, means the same here as &lt;code&gt;try&lt;/code&gt; in other languages) รขโฌโ and I might as well have written

&lt;code&gt;my $name = eval { $product-&gt;offering-&gt;merchant-&gt;name };&lt;/code&gt;

To keep with &lt;code&gt;reduce&lt;/code&gt;, it would have to be something like &lt;code&gt;$a &amp;&amp; $a-&gt;$b()&lt;/code&gt; as the reduce block.</description>
		<content:encoded><![CDATA[<p>Hmm, now that I come back to look at it with fresh mind, it occurs to me that I led me <code>reduce</code> abstraction ad absurdum the moment I used <code>eval</code> (which, for non-Perl folks, means the same here as <code>try</code> in other languages) &Atilde;&cent;&acirc;&not;&acirc; and I might as well have written</p>
<p><code>my $name = eval { $product-&amp;gt;offering-&amp;gt;merchant-&amp;gt;name };</code></p>
<p>To keep with <code>reduce</code>, it would have to be something like <code>$a &amp;amp;&amp;amp; $a-&amp;gt;$b()</code> as the reduce block.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aristotle Pagaltzis</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-359</link>
		<dc:creator>Aristotle Pagaltzis</dc:creator>
		<pubDate>Wed, 19 Dec 2007 18:45:14 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-359</guid>
		<description>To further reduce the repetition (pun intended):

&lt;code&gt;my $name = (
	reduce { eval { $a-&gt;$b() } }
	$product,
	qw( offering merchant name ),
);

display_merchant_name($name) if defined $name;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>To further reduce the repetition (pun intended):</p>
<p><code>my $name = (<br />
	reduce { eval { $a-&amp;gt;$b() } }<br />
	$product,<br />
	qw( offering merchant name ),<br />
);</p>
<p>display_merchant_name($name) if defined $name;</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: the_dormant</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-358</link>
		<dc:creator>the_dormant</dc:creator>
		<pubDate>Wed, 19 Dec 2007 14:27:19 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-358</guid>
		<description>sorry but the last comment didn&#039;t work
object NarrativeMismatch{
  case class Product(offering:Option[Offering])
  case class Offering(merchant:Option[Merchant])
  case class Merchant(name : String)

  def merchantName(maybeProduct: Option[Product]) : Option[String] =
    for (val product  &lt;- maybeProduct ;
	 val offering &lt;- product.offering;
	 val merchant &lt;- offering.merchant)
      yield merchant.name
}</description>
		<content:encoded><![CDATA[<p>sorry but the last comment didn&#8217;t work<br />
object NarrativeMismatch{<br />
  case class Product(offering:Option[Offering])<br />
  case class Offering(merchant:Option[Merchant])<br />
  case class Merchant(name : String)</p>
<p>  def merchantName(maybeProduct: Option[Product]) : Option[String] =<br />
    for (val product  &lt;- maybeProduct ;<br />
	 val offering &lt;- product.offering;<br />
	 val merchant &lt;- offering.merchant)<br />
      yield merchant.name<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: the_dormant</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-357</link>
		<dc:creator>the_dormant</dc:creator>
		<pubDate>Wed, 19 Dec 2007 14:23:50 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-357</guid>
		<description>&lt;code&gt;

don&#039;t know if it&#039;s simpler but again in scala :
object NarrativeMismatch{
  case class Product(offering:Option[Offering])
  case class Offering(merchant:Option[Merchant])
  case class Merchant(name : String)

  def merchantName(maybeProduct: Option[Product]) : Option[String] =
    for (val product
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p><code></p>
<p>don't know if it's simpler but again in scala :<br />
object NarrativeMismatch{<br />
  case class Product(offering:Option[Offering])<br />
  case class Offering(merchant:Option[Merchant])<br />
  case class Merchant(name : String)</p>
<p>  def merchantName(maybeProduct: Option[Product]) : Option[String] =<br />
    for (val product<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver</title>
		<link>http://osteele.com/archives/2007/12/cheap-monads/comment-page-1#comment-356</link>
		<dc:creator>Oliver</dc:creator>
		<pubDate>Wed, 19 Dec 2007 05:49:56 +0000</pubDate>
		<guid isPermaLink="false">http://osteele.com/2007/12/17/monads-on-the-cheap-i-the-maybe-monad#comment-356</guid>
		<description>Hi, David!  Good to hear from you again.

the_dormant: Okay, that does it.  I&#039;ll finally at scala.

Alan, Thomas, thanks for the comments.  Something that makes me uncomfortable about catching exceptions is that it has dynamic scope.  If the accessors don&#039;t run any code, it&#039;s the same thing, but if product.offering is a getter that includes the expression record.connection, then the rescue will hide the case where record is null, as well as the case where product is null.

Alan: After I wrote this I found this post http://weblog.raganwald.com/2007/04/writing-programs-for-people-to-read.html on Raganwald, which covered the &quot;narrative mismatch&quot; earlier and better.  Braithwaite summarizes a post by Norbert Winklareth as being about &quot;minimizing the semantic distance between the program as written and the solution to the problem as conceived by the programmer&quot;.</description>
		<content:encoded><![CDATA[<p>Hi, David!  Good to hear from you again.</p>
<p>the_dormant: Okay, that does it.  I&#8217;ll finally at scala.</p>
<p>Alan, Thomas, thanks for the comments.  Something that makes me uncomfortable about catching exceptions is that it has dynamic scope.  If the accessors don&#8217;t run any code, it&#8217;s the same thing, but if product.offering is a getter that includes the expression record.connection, then the rescue will hide the case where record is null, as well as the case where product is null.</p>
<p>Alan: After I wrote this I found this post <a href="http://weblog.raganwald.com/2007/04/writing-programs-for-people-to-read.html">http://weblog.raganwald.com/2007/04/writing-programs-for-people-to-read.html</a> on Raganwald, which covered the &#8220;narrative mismatch&#8221; earlier and better.  Braithwaite summarizes a post by Norbert Winklareth as being about &#8220;minimizing the semantic distance between the program as written and the solution to the problem as conceived by the programmer&#8221;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

