title: Filter in List with custom data types
body: <p>I have just started using Haskell. And I am using it for log parsing, and I am trying to filter the log. but getting error related to TypeMismatch.</p>
  
  <p>Here is what I did.</p>
  
  <p><strong>my data types</strong></p>
  
  <pre><code>data LogExStack = LogExStack {
      methodName :: String,
      className :: String,
      extraInfo :: String
  } | List [LogExStack] deriving Show
  data LogException = LogException {
      exFirstLine :: LogExFirstLine,
      exMessage :: LogExMessage,
      exStackTrace :: LogExStack
  } deriving Show
  </code></pre>
  
  <p>I want to have the filter on <code>LogExStack</code> type data.
  and my function for creating that list looks something like this</p>
  
  <pre><code>exceptionStackTraceParser :: Parser LogExStack
  exceptionStackTraceParser =
      M.liftM List $ sepBy exceptionParser newLinesTabEx
  
  
  exceptionParser :: Parser LogExStack
  exceptionParser =
      do
          string "at"
          method &lt;- many (noneOf "(")
          string "("
          className &lt;- many (noneOf ")")
          string ")"
          extraInfo &lt;- many (noneOf "\n")
          string "\n"
          return $ LogExStack method className extraInfo
  </code></pre>
  
  <p>till now it's fine, but when I tried to use the list for filter it didn't work. I wanted to have filter on the methodName from LogExStack list.</p>
  
  <p>here is my function for that</p>
  
  <pre><code>filterStackTrace :: [LogExStack] -&gt; [LogExStack]
  filterStackTrace  = filter (\r -&gt; methodName r == "com.xyz.abc")
  </code></pre>
  
  <p>I also tried without [] but it failed as well. can anyone help me with this.
  I took the reference for my implementation from here</p>
  
  <p><a href="https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours/Parsing" rel="nofollow noreferrer">https://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours/Parsing</a></p>
  
  <p><a href="https://stackoverflow.com/questions/20653830/filter-a-haskell-data-type">Filter a haskell data type</a></p>
  
  <p>can anyone help me with this?
  Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>here is the changes I make after reading Arnon post</p>
  
  <pre><code>exceptionStackTraceParser :: Parser [LogExStack]
  exceptionStackTraceParser =
      sepBy exceptionParser newLinesTabEx
  </code></pre>
  
  <p>here is how I am calling filter</p>
  
  <pre><code>parseExpr :: Parser LogException
  parseExpr = 
      do
          fstLine &lt;- exceptionFirstLineParser
          msgLine &lt;- exceptionMessageParser
          stackTrace &lt;- exceptionStackTraceParser
          list &lt;- filterStackTrace stackTrace
          return $ LogException fstLine msgLine list
  </code></pre>
  
  <p>and here is my exception</p>
  
  <pre><code>H:\&gt;ghc --make -O logparser.hs
  [1 of 1] Compiling Main             ( logparser.hs, logparser.o )
  
  logparser.hs:69:25:
      Couldn't match type `[]'
                    with `Text.Parsec.Prim.ParsecT
                            String () Data.Functor.Identity.Identity'
      Expected type: Text.Parsec.Prim.ParsecT
                       String () Data.Functor.Identity.Identity LogExStack
        Actual type: [LogExStack]
      In a stmt of a 'do' block: list &lt;- filterStackTrace stackTrace
      In the expression:
        do { fstLine &lt;- exceptionFirstLineParser;
             msgLine &lt;- exceptionMessageParser;
             stackTrace &lt;- exceptionStackTraceParser;
             list &lt;- filterStackTrace stackTrace;
             .... }
  </code></pre>
  
  <p><strong>EDIT2</strong>
  Got it I was calling the list filter from wrong place somehow I can not call from the parseExpr function, because I don't know somehow it thinks called function from there must be Parsec type. </p>
  
  <p>I don't know why? can anybody help me understand that?</p>