Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe20.iad.POSTED!8ad76e89!not-for-mail From: Arved Sandstrom User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Call by Result References: <95e4uuF3cvU1@mid.individual.net> <8CtIp.4644$PA5.4578@newsfe01.iad> <4df5290c$0$49183$e4fe514c@news.xs4all.nl> <4df77a95$0$49041$e4fe514c@news.xs4all.nl> In-Reply-To: <4df77a95$0$49041$e4fe514c@news.xs4all.nl> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Lines: 57 Message-ID: <_XPJp.2060$g12.487@newsfe20.iad> X-Complaints-To: abuse@newsgroups-download.com NNTP-Posting-Date: Tue, 14 Jun 2011 20:58:34 UTC Organization: Public Usenet Newsgroup Access Date: Tue, 14 Jun 2011 17:58:33 -0300 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5312 On 11-06-14 12:13 PM, Silvio wrote: > On 06/14/2011 12:52 PM, Andreas Leitgeb wrote: >> Silvio wrote: >>> Well, here is an example in Scala: >>> [...] >>> def getString(s : String) : Option[String] = >>> { >>> if (s.reverse == s) Some(s.toLowerCase) >>> else None >>> } >>> [...] >>> val t = getString(s) >>> [...] >>> t match >>> { >>> case Some(r) => println("Success, return value is: " + r) >>> case None => println("Failure") >>> } >> >> Ah, thanks. Yep, I've seen this concept once when playing with >> OCaml (which mentions Haskell as one of its roots). Never got >> warm with it, though. >> >> In the end, it isn't all that more concise than C++/Java... >> It's a bit like C's unions with some byte ahead to tell which >> of the variants is the current one, and bunch of logical operations >> that is often trivially converted into a couple of (possibly nested) >> "if-else"s. I'm not saying it's bad, just it didn't impress me all >> that much, so far. >> > [ SNIP ] > Only when used in combination with other monads does Option shine. > > Pattern matching is very powerful because it unifies matching on types > and values AND extracting sub-values from matched values. But it would > deserve better examples than the one I provided. > > One would have to consider a larger piece of code to appreciate it as a > whole instead of looking at isolated language features. +1. Either larger chunks of code, and/or chaining of operations. With Option or Maybe, you don't have to check every intermediate result. With idiomatic Haskell or Scala you'd probably not see a whole bunch of pattern matching for Maybe or Option at all. It's way more concise than Java, and another advantage still remains that we're not looking for a special value (null). > Cheers, > > Silvio AHS