<?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"
	>
<channel>
	<title>Comments on: Maybe in Java</title>
	<atom:link href="http://blog.tmorris.net/maybe-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/maybe-in-java/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Fri, 05 Dec 2008 08:58:57 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: &#8220;For&#8221; hack with Option monad in Java at Stephans Blog</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-4938</link>
		<dc:creator>&#8220;For&#8221; hack with Option monad in Java at Stephans Blog</dc:creator>
		<pubDate>Wed, 06 Aug 2008 09:11:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-4938</guid>
		<description>[...] posts like the one from James show how to use options in Java. All have the problem that you need to unwrap the value inside the option / maybe. Scala ans Haskell do that [...]</description>
		<content:encoded><![CDATA[<p>[...] posts like the one from James show how to use options in Java. All have the problem that you need to unwrap the value inside the option / maybe. Scala ans Haskell do that [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: λ Tony’s blog λ &#187; Blog Archive &#187; Revisiting Maybe in Java</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-2520</link>
		<dc:creator>λ Tony’s blog λ &#187; Blog Archive &#187; Revisiting Maybe in Java</dc:creator>
		<pubDate>Wed, 30 Jul 2008 03:36:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-2520</guid>
		<description>[...] Tony’s blog λ The weblog of Tony Morris      &#171; Maybe in Java Australians in sport [...]</description>
		<content:encoded><![CDATA[<p>[...] Tony’s blog λ The weblog of Tony Morris      &laquo; Maybe in Java Australians in sport [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#38;nbsp; Algebraic Data Types again&#38;nbsp;by&#38;nbsp;λ Tony&#38;#8217;s blog λ</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-28</link>
		<dc:creator>&#38;nbsp; Algebraic Data Types again&#38;nbsp;by&#38;nbsp;λ Tony&#38;#8217;s blog λ</dc:creator>
		<pubDate>Sat, 04 Aug 2007 04:23:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-28</guid>
		<description>[...] If we consider a Java or C# class that can somehow enforce 2 and only 2 subclasses, then we could emulate closed algebraic data types in these languages. Indeed, it is possible to do so, however, you have to get really quirky with the language at hand. I have written about this before, but instead of using this trick, I am going to invent a new keyword for these languages called klass. [...]</description>
		<content:encoded><![CDATA[<p>[...] If we consider a Java or C# class that can somehow enforce 2 and only 2 subclasses, then we could emulate closed algebraic data types in these languages. Indeed, it is possible to do so, however, you have to get really quirky with the language at hand. I have written about this before, but instead of using this trick, I am going to invent a new keyword for these languages called klass. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-27</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Fri, 26 Jan 2007 00:17:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-27</guid>
		<description>But Bill, you have assumed I even have a problem - I simply don't. I don't use Java anymore. In fact, I used to work on the IBM implementation and I thankfully made the correct decision in leaving that behind.

I am not trying to fit anything anywhere; merely, provide a layperson perspective of an existing problem to the laypeople - the Java programmers.

I have absolutely no ambition of using Java as a functional language. OK, this is a bit of a lie, since I use &lt;a href="http://www.scala-lang.org/" rel="nofollow"&gt;Scala&lt;/a&gt; quite a lot these days - whose very existence refutes your claim that it cannot be done. You might also wish to refer to my post titled &lt;a href="http://blog.tmorris.net/fix-it-sun" rel="nofollow"&gt;Fix It Sun!&lt;/a&gt;, which outlines the single biggest bottleneck in software development progress - the inability to tail call on the Sun JVM (the IBM JVM works fine, so long as it is not an indirect tail call).

In the meantime, I will use Haskell/Scala et. al. and watch the Java programmers struggle with solving even the most basic of problems - that of partial function. I will make efforts to provide insight for those seek it of course, hence this post.</description>
		<content:encoded><![CDATA[<p>But Bill, you have assumed I even have a problem - I simply don&#8217;t. I don&#8217;t use Java anymore. In fact, I used to work on the IBM implementation and I thankfully made the correct decision in leaving that behind.</p>
<p>I am not trying to fit anything anywhere; merely, provide a layperson perspective of an existing problem to the laypeople - the Java programmers.</p>
<p>I have absolutely no ambition of using Java as a functional language. OK, this is a bit of a lie, since I use <a href="http://www.scala-lang.org/" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.scala-lang.org');" rel="nofollow">Scala</a> quite a lot these days - whose very existence refutes your claim that it cannot be done. You might also wish to refer to my post titled <a href="http://blog.tmorris.net/fix-it-sun"  rel="nofollow">Fix It Sun!</a>, which outlines the single biggest bottleneck in software development progress - the inability to tail call on the Sun JVM (the IBM JVM works fine, so long as it is not an indirect tail call).</p>
<p>In the meantime, I will use Haskell/Scala et. al. and watch the Java programmers struggle with solving even the most basic of problems - that of partial function. I will make efforts to provide insight for those seek it of course, hence this post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill G.</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-26</link>
		<dc:creator>Bill G.</dc:creator>
		<pubDate>Tue, 02 Jan 2007 21:25:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-26</guid>
		<description>Your problem is you are trying to fit a square peg in a round hole. Java is not a functional language, and attempts to fit it in your narrow veiw of what is proper will never work.</description>
		<content:encoded><![CDATA[<p>Your problem is you are trying to fit a square peg in a round hole. Java is not a functional language, and attempts to fit it in your narrow veiw of what is proper will never work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: λ Tony&#38;#8217;s blog λ &#38;#187; Blog Archive &#38;#187; Strong Type Systems</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-25</link>
		<dc:creator>λ Tony&#38;#8217;s blog λ &#38;#187; Blog Archive &#38;#187; Strong Type Systems</dc:creator>
		<pubDate>Mon, 01 Jan 2007 01:03:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-25</guid>
		<description>[...] Looking good so far. But don&#38;#8217;t be fooled - there is a huge problem. Namely, that the interface cannot be implemented correctly. Keeping with tradition, let&#38;#8217;s attempt to write the Maybe monad: [...]</description>
		<content:encoded><![CDATA[<p>[...] Looking good so far. But don&#38;#8217;t be fooled - there is a huge problem. Namely, that the interface cannot be implemented correctly. Keeping with tradition, let&#38;#8217;s attempt to write the Maybe monad: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: λ Tony&#38;#8217;s blog λ &#38;#187; Blog Archive &#38;#187; Maybe Monad in Java</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-24</link>
		<dc:creator>λ Tony&#38;#8217;s blog λ &#38;#187; Blog Archive &#38;#187; Maybe Monad in Java</dc:creator>
		<pubDate>Mon, 18 Dec 2006 04:09:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-24</guid>
		<description>[...] As I have shown previously, the problem of partial function in Java is not easily solved. The solution of the Maybe algebraic data type, while definitely superior to existing options, is cumbersome to implement and requires some functions defined over the type (isJust, isNothing, etc.) in order to be complete. As some point out, there is a preference for continuation passing to prevent the need for a cast (even though this case would be hidden). This prompted me to provide a more complete solution - which is still only a subset of a complete solution. [...]</description>
		<content:encoded><![CDATA[<p>[...] As I have shown previously, the problem of partial function in Java is not easily solved. The solution of the Maybe algebraic data type, while definitely superior to existing options, is cumbersome to implement and requires some functions defined over the type (isJust, isNothing, etc.) in order to be complete. As some point out, there is a preference for continuation passing to prevent the need for a cast (even though this case would be hidden). This prompted me to provide a more complete solution - which is still only a subset of a complete solution. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-23</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Thu, 16 Nov 2006 11:16:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-23</guid>
		<description>One more thing, what're your thoughts on Gilad Bracha's Pluggable Types?


http://bracha.org/pluggable-types.pdf</description>
		<content:encoded><![CDATA[<p>One more thing, what&#8217;re your thoughts on Gilad Bracha&#8217;s Pluggable Types?</p>
<p><a href="http://bracha.org/pluggable-types.pdf" onclick="javascript:pageTracker._trackPageview('/outbound/comment/bracha.org');" rel="nofollow">http://bracha.org/pluggable-types.pdf</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-22</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Thu, 16 Nov 2006 11:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-22</guid>
		<description>I don't think mine is quite a CPS, as the functions run aren't intended to have side-effects, although of course they can.

That's why the generic parameter R is declared on the method, so that you can call 'accept' and have it return anything.

You can use it like a CPS if you make R a Runnable, which I did for a short while, but, to be honest, I kept forgetting to tag '.run()' to the end. ;)

maybe.accept(functionThatReturnsARunnable,anotherRunnable).run();

A non-CPS use of the 'functional' Maybe:

For example, my automated tests operate on a JFrame.  I wrapped JFrame so that I can instantiate my version in 'headless' mode, but sometimes you need to get at the original JFrame, e.g., to pass a 'this' pointer to a layout manager.  So I have:

Maybe[javax.swing.JFrame] getRealFrame(); in my JFrame interface.

Suppose I want to find out whether the real frame is visible, and assume it's not if it doesn't exist.  In reality I can call 'isVisible()' on my own JFrame interface, but let's suppose I didn't implement that..

Function[JFrame,Boolean] isVisible=new Function[JFrame,Boolean]()
{
        public Boolean run(JFrame frame)
        {
                return frame.isVisible();
        }
};

frame.getRealFrame().accept(isVisible,false);

Of course, Java's syntax doesn't make the above function definition pretty.

It'd be nicer if we could use delegates:

frame.getRealFrame().accept(JFrame.isVisible,false);

or closures:

frame.getRealFrame().accept({t.isVisible()},false);

Of course, simply 'frame.isVisible()' is preferable there, instead of that whole line, as each implementation of my JFrame wrapper interface knows for definite (no Maybes about it) whether it has a real frame or not.

By the way, nice lambdas.  I'll try not to mistake them for a wishbone.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think mine is quite a CPS, as the functions run aren&#8217;t intended to have side-effects, although of course they can.</p>
<p>That&#8217;s why the generic parameter R is declared on the method, so that you can call &#8216;accept&#8217; and have it return anything.</p>
<p>You can use it like a CPS if you make R a Runnable, which I did for a short while, but, to be honest, I kept forgetting to tag &#8216;.run()&#8217; to the end. <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
maybe.accept(functionThatReturnsARunnable,anotherRunnable).run();</p>
<p>A non-CPS use of the &#8216;functional&#8217; Maybe:</p>
<p>For example, my automated tests operate on a JFrame.  I wrapped JFrame so that I can instantiate my version in &#8216;headless&#8217; mode, but sometimes you need to get at the original JFrame, e.g., to pass a &#8216;this&#8217; pointer to a layout manager.  So I have:</p>
<p>Maybe[javax.swing.JFrame] getRealFrame(); in my JFrame interface.</p>
<p>Suppose I want to find out whether the real frame is visible, and assume it&#8217;s not if it doesn&#8217;t exist.  In reality I can call &#8216;isVisible()&#8217; on my own JFrame interface, but let&#8217;s suppose I didn&#8217;t implement that..</p>
<p>Function[JFrame,Boolean] isVisible=new Function[JFrame,Boolean]()<br />
{<br />
        public Boolean run(JFrame frame)<br />
        {<br />
                return frame.isVisible();<br />
        }<br />
};</p>
<p>frame.getRealFrame().accept(isVisible,false);</p>
<p>Of course, Java&#8217;s syntax doesn&#8217;t make the above function definition pretty.</p>
<p>It&#8217;d be nicer if we could use delegates:</p>
<p>frame.getRealFrame().accept(JFrame.isVisible,false);</p>
<p>or closures:</p>
<p>frame.getRealFrame().accept({t.isVisible()},false);</p>
<p>Of course, simply &#8216;frame.isVisible()&#8217; is preferable there, instead of that whole line, as each implementation of my JFrame wrapper interface knows for definite (no Maybes about it) whether it has a real frame or not.</p>
<p>By the way, nice lambdas.  I&#8217;ll try not to mistake them for a wishbone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/maybe-in-java/#comment-21</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Wed, 15 Nov 2006 22:29:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/maybe-in-java/#comment-21</guid>
		<description>Hi Ricky,
I think your solution is not optimal and in fact, I did cover it when I said, "Emulate continuation passing style (CPS)". The drawbacks of this approach are something that I intend to cover in a more detailed document, nevertheless, the given Maybe implementation is not complete.

I only intended to point out that it is possible (though a poor man's implementation) to emulate an algebraic data type with Java. I intend to cover this topic much more thoroughly by first introducing intersection types [&lt;a href="http://citeseer.ist.psu.edu/pierce91programming.html" rel="nofollow"&gt;1&lt;/a&gt;] and working from there.</description>
		<content:encoded><![CDATA[<p>Hi Ricky,<br />
I think your solution is not optimal and in fact, I did cover it when I said, &#8220;Emulate continuation passing style (CPS)&#8221;. The drawbacks of this approach are something that I intend to cover in a more detailed document, nevertheless, the given Maybe implementation is not complete.</p>
<p>I only intended to point out that it is possible (though a poor man&#8217;s implementation) to emulate an algebraic data type with Java. I intend to cover this topic much more thoroughly by first introducing intersection types [<a href="http://citeseer.ist.psu.edu/pierce91programming.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/citeseer.ist.psu.edu');" rel="nofollow">1</a>] and working from there.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
