<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Michele Campeotto: Tag java</title>
    <link>http://blog.micampe.it/articles/tag/java?tag=java</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>I'm not Winston Wolfe.</description>
    <item>
      <title>Scala</title>
      <description>&lt;p&gt;I recently learned about &lt;a href="http://scala-lang.org"&gt;Scala&lt;/a&gt;, a language for the JVM which tries to smoothly integrate object oriented and functional programming features.&lt;/p&gt;

&lt;p&gt;I find it particularly interesting because of two reasons: first it is integrated with the Java platform and thus can use all the Java code already available. Second, it can be used almost as a Java evolution where you can gradually add functional concepts and more advanced features of the type system.&lt;/p&gt;

&lt;p&gt;Scala is a static language, and lately the whole world is excited about dynamic languages, so this might seem a bit backwards, but I think sane static languages have their place in the world. And Scala has some very nice features (pattern matching on objects, flexible syntax) to make it appealing to me. I&amp;#8217;d like to try to use it &lt;a href="http://www.h-care.it/"&gt;at work&lt;/a&gt;, integrating it with the bulk of Java code we already have.&lt;/p&gt;

&lt;p&gt;To experiment a bit with the language I tried translating some &lt;a href="http://en.literateprograms.org/Quicksort_%28Haskell%29"&gt;examples from Haskell&lt;/a&gt;. The result is kinda pointless and probably not a good example of Scala programming, but it helped me get a feeling of the language.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;package test.sort

object QuickSort {

  def qsort1[A &amp;lt;% Ordered[A]](xs: List[A]): List[A] = xs match {
    case y :: ys =&amp;gt; {
      val lt = for (val i &amp;lt;- ys; i &amp;lt; y) yield i;
      val gt = for (val i &amp;lt;- ys; i &amp;gt;= y) yield i;
      qsort1(lt) ::: List(y) ::: qsort1(gt)
    }
    case Nil =&amp;gt; Nil
  }

  def qsort2[A &amp;lt;% Ordered[A]](xs: List[A]): List[A] = xs match {
    case Nil =&amp;gt; Nil
    case z :: zs =&amp;gt; {
      def part(z: A, zs: List[A], parts: Tuple3[List[A], List[A], List[A]]): Tuple3[List[A], List[A], List[A]] = zs match {
        case Nil =&amp;gt; parts
        case y :: ys =&amp;gt; {
          if (y &amp;gt; z)
            part(z, ys, {parts._1, parts._2, y :: parts._3})
          else if (y &amp;lt; z) 
            part(z, ys, {y :: parts._1, parts._2, parts._3})
          else 
            part(z, ys, {parts._1, y :: parts._2, parts._3})
        }
      }
      val parts = part(z, zs, Tuple3(Nil, List(z), Nil))
      qsort2(parts._1) ::: parts._2 ::: qsort2(parts._3)
    }
  }

  def qsort3[A &amp;lt;% Ordered[A]](xs: List[A]): List[A] = {
    def qsort3b(ys: List[A], acc: List[A]): List[A] = ys match {
      case Nil =&amp;gt; acc
      case List(z) =&amp;gt; z :: acc
      case z :: zs =&amp;gt; {
        def part(ps: List[A], parts: Tuple3[List[A], List[A], List[A]]): List[A] = ps match {
          case Nil =&amp;gt; qsort3b(parts._1, parts._2 ::: qsort3b(parts._3, acc))
          case z :: zs =&amp;gt; {
            if (z &amp;gt; ys.head)
              part(zs, {parts._1, parts._2, z :: parts._3})
            else if (z &amp;lt; ys.head)
              part(zs, {z :: parts._1, parts._2, parts._3})
            else
              part(zs, {parts._1, z :: parts._2, parts._3})
          }
        }
        part(zs, {Nil, List(z), Nil})
      }
    }
    qsort3b(xs, Nil)
  }
}
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Wed, 21 Feb 2007 14:03:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:8c505b6f-48d4-4916-963f-a9deaa8b1ad1</guid>
      <author>micampe</author>
      <link>http://blog.micampe.it/articles/2007/02/21/scala</link>
      <category>English</category>
      <category>scala</category>
      <category>java</category>
      <category>haskell</category>
      <category>code</category>
      <category>programming</category>
      <trackback:ping>http://blog.micampe.it/articles/trackback/1072</trackback:ping>
    </item>
  </channel>
</rss>
