title: Returning <Case Class>.type with Case Class
body: <p>Given a case class:</p>
  
  <pre><code>scala&gt; case class Foo(x: Int, y: String)
  defined class Foo
  </code></pre>
  
  <p>I can define a method that returns <code>Either[Foo.type, ...]</code>.</p>
  
  <pre><code>scala&gt; def f: Either[Foo.type, Int] = Left(Foo)
  f: Either[Foo.type,Int]
  </code></pre>
  
  <p>When I tried to de-construct <code>Foo</code>, I saw a compile-time error:</p>
  
  <pre><code>scala&gt; f match { case Left(Foo(a, b)) =&gt; a }
  &lt;console&gt;:14: error: constructor cannot be instantiated to expected type;
   found   : Foo
   required: Foo.type
         f match { case Left(Foo(a, b)) =&gt; a }
  </code></pre>
  
  <p>But the following worked:</p>
  
  <pre><code>scala&gt; f match { case Left(foo) =&gt; foo }
  &lt;console&gt;:14: warning: match may not be exhaustive.
  It would fail on the following input: Right(_)
         f match { case Left(foo) =&gt; foo }
  res1: Foo.type = Foo
  </code></pre>
  
  <p>Given a <code>case class</code>, when is it appropriate to use a <code>&lt;CASE CLASS&gt;.type</code> type?</p>