title: scala error "pattern type is incompatible with expected type"
body: <p>I am working my way through the "Functional Programming in Scala" book. Chapter 5.2 starts with the following code:</p>
  
  <pre><code>sealed trait Stream[+A]
  case object Empty extends Stream[Nothing]
  case class Cons[+A](h: () =&gt; A, t: () =&gt; Stream[A]) extends Stream[A]
  
  object Stream {
    def cons[A](hd: =&gt; A, tl: =&gt; Stream[A]): Stream[A] = {
      lazy val head = hd
      lazy val tail = tl
      Cons(() =&gt; head, () =&gt; tail)
    }
  
    def empty[A]: Stream[A] = Empty
  
    def apply[A](as: A*): Stream[A] =
      if (as.isEmpty) empty else cons(as.head, apply(as.tail: _*))
  
  }
  </code></pre>
  
  <p>Then the following definition is given:</p>
  
  <pre><code>  def headOption: Option[A] = this match {
        case Empty =&gt; None
        case Cons(h, t) =&gt; Some(h())
      }
  </code></pre>
  
  <p>I assume it should be part of the companion object. To not get a compile error immediately I add "headOption[A]". But when I include the result into "object Stream" I am getting the error "pattern type is incompatible with expected type; found : myPackage.Empty.type required: myPackage.Stream.type" with "Empty" underlined.</p>
  
  <p>I am a little lost here. What am I doing wrong?</p>