<?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: The &#8220;Option&#8221; Pattern</title>
	<atom:link href="http://www.codecommit.com/blog/scala/the-option-pattern/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/the-option-pattern</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Sun, 29 Aug 2010 20:01:44 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3889</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Fri, 01 Aug 2008 16:44:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3889</guid>
		<description>Yeah, the fact that Java&#039;s generic only support use-point variance (rather than declaration-point) is a bit annoying here, leading to the extra verbosity in the syntax.  If Java had Nothing, then we could avoid the type parameter on None, but we would still require the extra [? extends Object] bit in order to simulate covariance.</description>
		<content:encoded><![CDATA[<p>Yeah, the fact that Java&#8217;s generic only support use-point variance (rather than declaration-point) is a bit annoying here, leading to the extra verbosity in the syntax.  If Java had Nothing, then we could avoid the type parameter on None, but we would still require the extra [? extends Object] bit in order to simulate covariance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3888</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Fri, 01 Aug 2008 15:43:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3888</guid>
		<description>Actually, it&#039;s this (using square brackets so they don&#039;t get eaten):

public static [T] Option[T] none() {return new None[T]();}

private Option[String] value = none();

and this would be illegal

private void foo(Option[Object] x) {...}
foo(value)

You have to write
private void foo(Option[? extends Object] x) {...}
foo(value)</description>
		<content:encoded><![CDATA[<p>Actually, it&#8217;s this (using square brackets so they don&#8217;t get eaten):</p>
<p>public static [T] Option[T] none() {return new None[T]();}</p>
<p>private Option[String] value = none();</p>
<p>and this would be illegal</p>
<p>private void foo(Option[Object] x) {&#8230;}<br />
foo(value)</p>
<p>You have to write<br />
private void foo(Option[? extends Object] x) {&#8230;}<br />
foo(value)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan Schmidt</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3887</link>
		<dc:creator>Stephan Schmidt</dc:creator>
		<pubDate>Fri, 01 Aug 2008 12:29:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3887</guid>
		<description>Yes Java is sometimes too verbose. But

  private Option value = new None();

can be replaced with 

  private Option value = none();

and

public static   Option none() { return new None(); }

Peace
-stephan</description>
		<content:encoded><![CDATA[<p>Yes Java is sometimes too verbose. But</p>
<p>  private Option value = new None();</p>
<p>can be replaced with </p>
<p>  private Option value = none();</p>
<p>and</p>
<p>public static   Option none() { return new None(); }</p>
<p>Peace<br />
-stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eamonn McManus</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3488</link>
		<dc:creator>Eamonn McManus</dc:creator>
		<pubDate>Tue, 15 Apr 2008 09:08:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3488</guid>
		<description>Rats. The two links that got eaten in my previous comment are:
http://www.artima.com/weblogs/viewpost.jsp?thread=221903
http://www.javac.info/bloch-closures-controversy.ppt</description>
		<content:encoded><![CDATA[<p>Rats. The two links that got eaten in my previous comment are:<br />
<a href="http://www.artima.com/weblogs/viewpost.jsp?thread=221903" rel="nofollow">http://www.artima.com/weblogs/viewpost.jsp?thread=221903</a><br />
<a href="http://www.javac.info/bloch-closures-controversy.ppt" rel="nofollow">http://www.javac.info/bloch-closures-controversy.ppt</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eamonn McManus</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3487</link>
		<dc:creator>Eamonn McManus</dc:creator>
		<pubDate>Tue, 15 Apr 2008 09:07:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3487</guid>
		<description>Tony,

I&#039;m actually not quite so extreme as to think there should be no innovation whatever in the Java language, but I wouldn&#039;t be particularly upset if that turned out to be the case. Bruce Eckel puts it well in . I also broadly agree with Josh Bloch&#039;s argument against the proposed closures extension at . However, change is always more exciting than stasis, so I ultimately expect reactionaries like me to be ignored.</description>
		<content:encoded><![CDATA[<p>Tony,</p>
<p>I&#8217;m actually not quite so extreme as to think there should be no innovation whatever in the Java language, but I wouldn&#8217;t be particularly upset if that turned out to be the case. Bruce Eckel puts it well in . I also broadly agree with Josh Bloch&#8217;s argument against the proposed closures extension at . However, change is always more exciting than stasis, so I ultimately expect reactionaries like me to be ignored.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3486</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Tue, 15 Apr 2008 08:11:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3486</guid>
		<description>&quot;I’m in the camp that thinks we should probably leave the Java language alone (no closures for me) and innovate in other languages such as Scala.&quot;

Eamonn,
Is there such a camp? On what forum do they put submit their interests? I can&#039;t find any. Are you worried about &quot;innovation&quot; being applied to Scala in the same way &quot;innovation&quot; has been applied to Java in the past? Reading the mailing lists in recent months, I certainly am. This puts me on the fence - maybe closures would ultimately be good for Java to appease my own personal interests.</description>
		<content:encoded><![CDATA[<p>&#8220;I’m in the camp that thinks we should probably leave the Java language alone (no closures for me) and innovate in other languages such as Scala.&#8221;</p>
<p>Eamonn,<br />
Is there such a camp? On what forum do they put submit their interests? I can&#8217;t find any. Are you worried about &#8220;innovation&#8221; being applied to Scala in the same way &#8220;innovation&#8221; has been applied to Java in the past? Reading the mailing lists in recent months, I certainly am. This puts me on the fence &#8211; maybe closures would ultimately be good for Java to appease my own personal interests.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eamonn McManus</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3485</link>
		<dc:creator>Eamonn McManus</dc:creator>
		<pubDate>Tue, 15 Apr 2008 07:59:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3485</guid>
		<description>Right, I realized in the meantime that my comment makes no sense in the language as it stands, because you want to be able to do e.g. Option[Boolean] value = new None[Boolean]. If instead None has no type parameter and extends Option[Void] then this assignment is incorrect. So Daniel&#039;s original suggestion is correct.

It can be made slightly less painful using static factory methods (with type inference) instead of or as well as public constructors, for example so you could write Option[Boolean] value = None.instance(). (You could even cheat horribly and have None.instance() always return the same object.)

Neal Gafter has been suggesting for some time that Java should acquire a name for the null type, probably &quot;null&quot;. So here we might write public class None extends Option[null], but as you note that would require writing Option[? extends Boolean] value = new None(), which is clunky.

As for me, I&#039;m in the camp that thinks we should probably leave the Java language alone (no closures for me) and innovate in other languages such as Scala.</description>
		<content:encoded><![CDATA[<p>Right, I realized in the meantime that my comment makes no sense in the language as it stands, because you want to be able to do e.g. Option[Boolean] value = new None[Boolean]. If instead None has no type parameter and extends Option[Void] then this assignment is incorrect. So Daniel&#8217;s original suggestion is correct.</p>
<p>It can be made slightly less painful using static factory methods (with type inference) instead of or as well as public constructors, for example so you could write Option[Boolean] value = None.instance(). (You could even cheat horribly and have None.instance() always return the same object.)</p>
<p>Neal Gafter has been suggesting for some time that Java should acquire a name for the null type, probably &#8220;null&#8221;. So here we might write public class None extends Option[null], but as you note that would require writing Option[? extends Boolean] value = new None(), which is clunky.</p>
<p>As for me, I&#8217;m in the camp that thinks we should probably leave the Java language alone (no closures for me) and innovate in other languages such as Scala.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3473</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Mon, 14 Apr 2008 18:27:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3473</guid>
		<description>In this comment I&#039;m also going to use square brackets instead of angled brackets in the Java code so they don&#039;t get eaten.

Java would definitely be improved with both Null and Void types (or whatever you want to call these types, in Scala they&#039;re called Null and Nothing).  As a small nit, the null type isn&#039;t quite the bottom type in Java because it&#039;s not a subtype of any of the primitive types.  Still, as a practical matter that wouldn&#039;t affect this discussion since primitive types can&#039;t be be used as parameters to type constructors in Java - e.g. in Java you can&#039;t have Option[int].

But even if Java had a denotable bottom type (say Void) or a nearly bottom type (say Null), Java&#039;s type system creates another pain-in-the-ass.  If class None extends Option[Void] then None would not be assignable to a variable of type Option[String] - you have to change the variable&#039;s type to Option[? extends String].  Without wildcard annotations, Java generics are invariant in their type parameters.  That means that to use such an Option type your Java code would be littered with wildcards.

That&#039;s the key reason Scala supports what it calls definition sight variance.  In Scala you define class Option[+T].  The plus means that the T parameter is covariant.   With it you&#039;ve got a nicely covariant parameterized type without using Scala&#039;s equivalent of Java wildcards (existential types) throughout your code.  Then Scala&#039;s type system prevents you from using a covariant type parameter in a contravariant way or vice versa and you can safely say

val x: Option[String] = None</description>
		<content:encoded><![CDATA[<p>In this comment I&#8217;m also going to use square brackets instead of angled brackets in the Java code so they don&#8217;t get eaten.</p>
<p>Java would definitely be improved with both Null and Void types (or whatever you want to call these types, in Scala they&#8217;re called Null and Nothing).  As a small nit, the null type isn&#8217;t quite the bottom type in Java because it&#8217;s not a subtype of any of the primitive types.  Still, as a practical matter that wouldn&#8217;t affect this discussion since primitive types can&#8217;t be be used as parameters to type constructors in Java &#8211; e.g. in Java you can&#8217;t have Option[int].</p>
<p>But even if Java had a denotable bottom type (say Void) or a nearly bottom type (say Null), Java&#8217;s type system creates another pain-in-the-ass.  If class None extends Option[Void] then None would not be assignable to a variable of type Option[String] &#8211; you have to change the variable&#8217;s type to Option[? extends String].  Without wildcard annotations, Java generics are invariant in their type parameters.  That means that to use such an Option type your Java code would be littered with wildcards.</p>
<p>That&#8217;s the key reason Scala supports what it calls definition sight variance.  In Scala you define class Option[+T].  The plus means that the T parameter is covariant.   With it you&#8217;ve got a nicely covariant parameterized type without using Scala&#8217;s equivalent of Java wildcards (existential types) throughout your code.  Then Scala&#8217;s type system prevents you from using a covariant type parameter in a contravariant way or vice versa and you can safely say</p>
<p>val x: Option[String] = None</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eamonn McManus</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3466</link>
		<dc:creator>Eamonn McManus</dc:creator>
		<pubDate>Mon, 14 Apr 2008 08:37:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3466</guid>
		<description>Grunt. My comment got mangled because I was unwise enough to use angle brackets. I meant to suggest that None should implement Option[Void], in which case it would be assignable to Option[T] without casting or generating compiler warnings.

Java does have an equivalent to the Nothing type, namely the null type (the type of the expression &quot;null&quot;), but because you can&#039;t name it its utility is somewhat limited. As you are aware, using null would have been an alternative in your Boolean case, though decidedly error-prone so I&#039;m not suggesting it would have been a better alternative.</description>
		<content:encoded><![CDATA[<p>Grunt. My comment got mangled because I was unwise enough to use angle brackets. I meant to suggest that None should implement Option[Void], in which case it would be assignable to Option[T] without casting or generating compiler warnings.</p>
<p>Java does have an equivalent to the Nothing type, namely the null type (the type of the expression &#8220;null&#8221;), but because you can&#8217;t name it its utility is somewhat limited. As you are aware, using null would have been an alternative in your Boolean case, though decidedly error-prone so I&#8217;m not suggesting it would have been a better alternative.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/the-option-pattern/comment-page-1#comment-3457</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Fri, 11 Apr 2008 15:31:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/the-option-pattern#comment-3457</guid>
		<description>It&#039;s parameterized so that I can assign it to variables of type Option[T] without casting.  It does make the syntax more verbose, but it&#039;s kinda necessary.  If Java had an equivalent to the Nothing type, we&#039;d be able to use that and there would be no need to explicitly parameterize None.</description>
		<content:encoded><![CDATA[<p>It&#8217;s parameterized so that I can assign it to variables of type Option[T] without casting.  It does make the syntax more verbose, but it&#8217;s kinda necessary.  If Java had an equivalent to the Nothing type, we&#8217;d be able to use that and there would be no need to explicitly parameterize None.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
