title: mutually recursive types in scala
body: <p>Is it possible to have mutual recursive types in scala?</p>
  
  <p>I have a xml files with a list of bugtracker issues. It's raw data. The model has different issue-types like "tasks", "subtasks", "bug", "special-bug".</p>
  
  <p>Now I want to parse my raw-data to a hierarchical structure of tasks and subtasks:</p>
  
  <pre><code>// data type for field contents
  abstract class Field
  case class Id(raw : string) extends Field
  case class Status(raw : string) extends Field
  ...
  
  // data type for primary model
  abstract class Issue(id : String, ...)
  case class Task(id : Id, status : Status ..., subtasks : List[Subtask] ) extends Issue(id, ...)
  case class Subtask(id : Id, status : Status ..., parent: Task) extends Issue(id, ...)
  </code></pre>
  
  <p>I wonder if this mutual recursion is theoretically possible?</p>
  
  <p>Second question:</p>
  
  <p>I render the model to some wiki-markup. This works fine with an overloaded recursive render() : String in the class for the datatype. (Probably I should have a "Renderable" Superclass !?)</p>
  
  <p>What would be the cleanest way for parsing, i.e. I'd like to have a recursive </p>
  
  <pre><code>fromXML : scala.xml.Elem =&gt; Issue / Field
  </code></pre>
  
  <p>Where would I put it? How would it look like? IIUC, the companion is autogenerated for case-classes so I cant add to it?</p>
  
  <p>I have this e.g.:</p>
  
  <pre><code>def fromXml(e : Elem) = e match {
    case &lt;a&gt;test&lt;/a&gt; =&gt; Id("test") 
    case _ =&gt; Status("Pre-analysed")
  }
  </code></pre>
  
  <p>But I failed to give the function a type. What <em>is</em> the type of that function ?</p>
  
  <p>I also thought about passing the xml-elem directly to the constructor of the ADT, would that be clever? Or should I separate XML-parsing and model-creation ?</p>
  
  <hr>
  
  <p>Jesus, after learning the scala basics and doing some scripts and functions (and thinking too much java), I finally understood how to write ADTs and can express myself nearly as in good old Haskell times :-)</p>