title: Problems with Haskell's Parsec <|> operator
body: <p>I am new to both Haskell and Parsec.  In an effort to learn more about the language and that library in particular I am trying to create a parser that can parse Lua saved variable files.  In these files variables can take the following forms:</p>
  
  <p>varname = value</p>
  
  <p>varname = {value, value,...}  </p>
  
  <p>varname = {{value, value},{value,value,...}}  </p>
  
  <p>I've created parsers for each of these types but when I string them together with the choice &lt;|> operator I get a type error.</p>
  
  <pre><code>Couldn't match expected type `[Char]' against inferred type `Char'
    Expected type: GenParser Char st [[[Char]]]
    Inferred type: GenParser Char st [[Char]]
  In the first argument of `try', namely `lList'
  In the first argument of `(&lt;|&gt;)', namely `try lList'
  </code></pre>
  
  <p>My assumption is (although I can't find it in the documentation) that each parser passed to the choice operator must return the same type.
  Here's the code in question:</p>
  
  <pre><code>data Variable = LuaString ([Char], [Char])
            | LuaList ([Char], [[Char]])
            | NestedLuaList ([Char], [[[Char]]])
            deriving (Show)
  
  main:: IO()
  main = do
         case (parse varName "" "variable = {{1234,\"Josh\"},{123,222}}") of
              Left err -&gt; print err
              Right xs -&gt; print xs 
  
  varName :: GenParser Char st Variable
  varName = do{
          vName &lt;- (many letter);
          eq &lt;- string " = ";
          vCon &lt;- try nestList
               &lt;|&gt; try lList 
               &lt;|&gt; varContent;
          return (vName, vCon)}
  
  varContent :: GenParser Char st [Char]
  varContent =  quotedString 
      &lt;|&gt; many1 letter
      &lt;|&gt; many1 digit
  
  quotedString :: GenParser Char st [Char]
  quotedString = do{
           s1 &lt;- string "\""; 
           s2 &lt;- varContent;
           s3 &lt;- string "\"";
           return (s1++s2++s3)}
  
  lList :: GenParser Char st [[Char]]
  lList = between (string "{") (string "}") (sepBy varContent (string ","))
  
  nestList :: GenParser Char st [[[Char]]]
  nestList = between (string "{") (string "}") (sepBy lList (string ","))
  </code></pre>