I'm working through the Essential Scala textbook from Underscore, and when I try to use one of the examples from the command line using the :load command I get errors. [edit] I said command line, I meant console.
I have put the code into a file by itself, and then have tried to use it using the :load command.
sealed trait IntList {
def product: Int =
this match {
case End => 1
case Pair(hd, tl) => hd * tl.product
}
}
case object End extends IntList
final case class Pair(head: Int, tail: IntList) extends IntList
I expected the code to compile and be usable, but I get these messages:
error: pattern type is incompatible with expected type;
found : End.type
required: IntList
case End => 1
and
error: constructor cannot be instantiated to expected type;
found : Pair
required: IntList
case Pair(hd, tl) => hd * tl.product