title: Scala execution of abstract classes with case
body: <p>I'm new to Scala and I am following this tutorial <a href="http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html" rel="nofollow">http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html</a> in which there is an example of case class usage.</p>
  
  <p>I was trying to execute the example below:</p>
  
  <pre><code>package classes
  
  abstract class Tree 
  case class Sum(l: Tree, r: Tree) extends Tree
  case class Var(n: String) extends Tree
  case class Const(v: Int) extends Tree {
  
      type Environment = String =&gt; Int
  
      def eval(t: Tree, env: Environment): Int = t match {
          case Sum(l, r) =&gt; eval(l, env) + eval(r, env)
          case Var(n) =&gt; env(n)
          case Const(v) =&gt; v
      }
  }
  </code></pre>
  
  <p>But the thing is that I couldn't execute it and I suspect that the reason is that I cannot add a main method there because it is a class and not an object. So I created an object with a main method there:</p>
  
  <pre><code>package classes
  
  object TreeOperations {
      type Environment = String =&gt; Int //XXX: cannot I import it somehow?
  
      def main(args: Array[String]) {    
        // evaluating (x+x)+(7+y) expression
          val exp: Tree = Sum(Sum(Var("x"), Var("x")),Sum(Const(7), Var("y")))
          val env: Environment = { case "x" =&gt; 5 case "y" =&gt; 7} // x := 5, y := 7
          println("Expression: " + exp)
          println("Evaluation with x=5, y=7: " + eval(exp, env)) //XXX no eval here
      }
  }
  </code></pre>
  
  <p>But then I noticed two things:</p>
  
  <ol>
  <li><p>I cannot get access to type Environment because it is a differnent class (I tried Tree.Environment but it didn't work).</p></li>
  <li><p>I cannot get access to eval(...) as well (and I tried the same).</p></li>
  </ol>
  
  <p>So I wanted to know what would be the best way of solving these difficulties.</p>
  
  <p>Thanks in advance!</p>