Using Parsec for lexing&parsing
I've solved it by using Text.ParserCombinators.Parsec.GeneralizedToken from MissingH package:

psOpBracket = tokeng (\x -&gt; case x of TokOpBracket -&gt; Just Nothing ; _ -&gt; Nothing)


I had to use tokenPrim for cases when Token constructor takes arguments, though.