Writing a parser using applicative functors