Using Applicative notation for parsers whose result is discarded

applicative, haskell, parsec, refactoring

Solution

You can use `*>` and `<*` to include actions whose result is discarded (but their effect is run):

(*>) :: f a -> f b -> f b
(<*) :: f a -> f b -> f a

giving

filePath :: GenParser Char st Info
filePath = optional "./" *> Song <$> artist <*> slash *> album <*> slash *> track

Problem

I have a question on refactoring Parsec code to use the `Applicative` interface. Suppose I have a parser using the monadic interface like this: ``` filePath0 :: GenParser Char st Info filePath0 = do optional (string "./") r <- artist slash l <- album slash t <- track return $ Song r l t ``` I'd like to turn it into something like this: ``` filePath :: GenParser Char st Info filePath = Song <$> artist <*> album <*> track ``` But as you can see it is not complete. My question: where, in this refactored version, would I insert `optional (string "./")` and `slash` parsers?

Original source