Calling methods in a companion object
<p>Im new to learning scala, and working thorough the book <em>Functional Programming in Scala</em>.  I'm having some conceptual and programming issues working out how to test my solutions to exercises, which relate to how to properly call methods defined in companion object.</p>

<p>I have the following data type <code>MyList</code> that I have defined following along with the book</p>

<pre><code>sealed trait MyList[+A]
case object Nil extends MyList[Nothing]
case class Cons[+A](head: A, tail: MyList[A]) extends MyList[A]

object MyList {

    def apply[A](as: A*): MyList[A] = {
        if (as.isEmpty) Nil
        else Cons(as.head, apply(as.tail: _*))
    }

    def sum(ints: MyList[Int]): Int = ints match {
        case Nil =&gt; 0
        case Cons(x, xs) =&gt; x + sum(xs)
    }

    def product(ds: MyList[Double]): Double = ds match {
        case Nil =&gt; 1
        case Cons(x, xs) =&gt; x * product(xs)
    }

}
</code></pre>

<p>I would like to test my implementation of the methods <code>apply</code>, <code>sum</code> and <code>product</code> in the companion object.  To this end, I have added the following lines (these ones work) to the file after the object definition</p>

<pre><code>val x = MyList(1, 2, 3, 4)
println(x)
</code></pre>

<p>If I run these (I'm a command line type person, so this is though a bash shell session) it seems to work as I would expect</p>

<pre><code>$ scala ch3-list.scala
Cons(1,Cons(2,Cons(3,Cons(4,Nil))))
</code></pre>

<p>But I'm having trouble with the other two functions.  Ive tried the following combinations</p>

<pre><code>println(x.sum())
println(sum(x))
println(x.sum(x))
println(x.sum)
</code></pre>

<p>and they all give me errors.  For example, <code>x.sum()</code>, which I thought was most likely to work, gives</p>

<pre><code>$ scala ch3-list.scala
/Users/matthewdrury/Projects/fp-in-scala/ch3-list.scala:28: error: value sum is not a member of this.MyList[Int]
println(x.sum())
          ^
</code></pre>

<p>I'm new to scala, and have no java experience either, so the scoping rules are still fuzzy to me.  I'd like to know what I'm missing here conceptually, and get some advice on the best workflow to setup to test further methods of this kind.</p>