title: Using Parsec to parse configurations
body: <p>Here I have in mind that a possible configuration is a tree of specifications, each specification has a corresponding keyword (the string) and type. Something like this:</p>
  
  <pre><code>data Select = And | Or
  data ConfigTree = Node Select [ConfigTree] | Leaf (String, *)
  </code></pre>
  
  <p>I'm not sure how to write this properly, given that there's no "type of types", but nevermind that for the moment.</p>
  
  <p>Now, given such a tree, I want to build a parser that can read a possible valid configuration; I assume I already have sub-parsers that can parse keyword/type pairs.</p>
  
  <p>For instance, a possible configuration tree is:</p>
  
  <pre><code>Node And [ Leaf ("width", Double)
           , Node Or [ Leaf ("height", Double) , Leaf ("aspectratio", Double)
           ]
  </code></pre>
  
  <p>which can specify the size of a rectangle. A possible configuration file would be, say:</p>
  
  <pre><code>aspectratio = 2
  width = 10
  </code></pre>
  
  <p>(Let's assume that a configuration file is just a list of newline separated pairs, keyword = blah, where blah is something the corresponding parser for that keyword can deal with; but they can be in any order, and just have to match up with one possible "valid subset" of the tree, where a valid subset is any subset containing the top node, that contains all the children of an "and" node it contains, and say exactly one child of an "or" node it contains.)</p>
  
  <p>I have no idea how to even start building such a parser. Can anyone give some tips about how to proceed, or a way to completely restructure the above ConfigTree datatype to something more amenable to parsing?</p>