tag:blogger.com,1999:blog-6374583985636407395.post7322906011603409181..comments2008-04-02T04:59:24.592-07:00Comments on Scala Blog: Roman numerals in ScalaDavid Pollakhttp://www.blogger.com/profile/16630520857988769066noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-6374583985636407395.post-64504727962549569182008-04-02T04:59:00.000-07:002008-04-02T04:59:00.000-07:00In the definition of "unfold""case Some(r, v)" sho...In the definition of "unfold"<BR/>"case Some(r, v)" should actually be<BR/>"case Some((r, v))" (extra parenthesis).alhttp://www.blogger.com/profile/00165849288213425324noreply@blogger.comtag:blogger.com,1999:blog-6374583985636407395.post-9478918309665082582008-01-30T17:10:00.000-08:002008-01-30T17:10:00.000-08:00Incidentally, there is a deep category-theoretical...Incidentally, there is a deep category-theoretical foundation to the <B>unfold</B> operation: it's formally known as a <A HREF="http://en.wikipedia.org/wiki/Anamorphism" REL="nofollow">anamorphism</A> (or sometimes the lens operator).<BR/><BR/>The classic paper <A HREF="http://citeseer.ist.psu.edu/meijer91functional.html" REL="nofollow"><I>Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire</I></A> provides great insight into several standard recursive operators, and should be considered required reading for serious functional programmers.<BR/><BR/>I'm surprised to hear that Scala lacks <B>unfold</B>: I hope it will appear in a future release!Sarah Ahttp://www.blogger.com/profile/08930535728736959509noreply@blogger.comtag:blogger.com,1999:blog-6374583985636407395.post-31627379413081803552008-01-23T10:13:00.000-08:002008-01-23T10:13:00.000-08:00Interesting piece of code, I found it useful to g...Interesting piece of code, I found it useful to get my head around it. And after taking a quick look at Daniel's deromanize function, I tried to make it myself without peeking. It took a few tries... and peeks... but well, that's how you learn! At some point I'll be able to write stuff like that more naturally.<BR/>My favorite parts from ScalaByExample were the exercises... can you guys come up with some in this blog?? That's valuable training!Germánhttp://www.blogger.com/profile/07765922715981210093noreply@blogger.comtag:blogger.com,1999:blog-6374583985636407395.post-56066712712656577222008-01-16T23:47:00.000-08:002008-01-16T23:47:00.000-08:00def deromanize(roman : String) : int = numeral...def deromanize(roman : String) : int = <BR/> numerals.filter(roman startsWith _._1).sort(_._1.length > _._1.length) match {<BR/> case (s, v) :: _ => v + deromanize(roman.substring(s.length))<BR/> case Nil => 0<BR/> }<BR/> <BR/>woo!Daniel Greenhttp://www.blogger.com/profile/12330531444698401088noreply@blogger.comtag:blogger.com,1999:blog-6374583985636407395.post-79870697561803567692008-01-14T09:48:00.000-08:002008-01-14T09:48:00.000-08:00Ah nm.. got it: The first '_' is the normal scala ...Ah nm.. got it: <BR/><BR/>The first '_' is the normal scala shorthand for the first parameter of the anonymous function. <BR/><BR/>The second '_' is part of the '_2' val, that returns the second part of the tuple. The '_' in '_2' threw me off.Maurice Codikhttp://www.blogger.com/profile/05885954890842001668noreply@blogger.comtag:blogger.com,1999:blog-6374583985636407395.post-1058542488949126232008-01-14T09:33:00.000-08:002008-01-14T09:33:00.000-08:00Cool stuff. In the definition of "next", could you...Cool stuff. In the definition of "next", could you explain how the '_._2 <= in' part works? It's the only part thats a little unclear to me..Maurice Codikhttp://www.blogger.com/profile/05885954890842001668noreply@blogger.com