title: Idiomatic way to define s-expr in Scala
body: <p>How does Scala "want" me to define <a href="https://en.wikipedia.org/wiki/S-expression" rel="nofollow">s-expr</a>? In English, we define s-expr recursively, like this: "An s-expr is either an atom or a list of s-exprs." How do you say that in Scala?</p>
  
  <p>I'm pretty sure this is wrong:</p>
  
  <pre><code>// Scala 2.11.2
  trait Sexpr
  
  case class Atom(text: String) extends Sexpr
  
  type List[Sexpr] = Sexpr  // To my amazement, the compiler accepts this!
  
  val blah = Atom("blah")
  
  def matchtest(sexpr: Sexpr): Unit = sexpr match  {
    case blah :: Nil =&gt; println(blah)  // But the compiler won't accept this
    case _ =&gt; println("no match")
  }
  
  matchtest(List(Atom("blah")))
  </code></pre>
  
  <p><code>Either</code> is probably not a good fit for this, either, since then I'd have to distinguish between <code>Left</code> and <code>Right</code>, which is beside the point.</p>
  
  <p>How do you make a recursive class definition like this so that it works nicely with the rest of Scala?</p>