So I'm creating a basic parser in Haskell, and I recently learned that instead of something like this:
sumParser = fmap (\_ a _ b _ -> a + b) ws <*> val <*> plus <*> val <*> eof
I could make it cleaner using something like
sumParser = fmap (+) ws *> val <* plus *> val <* eof
Obviously, I'm not actually doing this, but it's an example. My question is, I can 'skip' the 'return' value of certain parsers(?) like ws
and val
using the <*
and *>
. However, I'm really new to Haskell, and I'm not sure if this even makes sense or how to look it up (I don't really get it from Hoogle and looking around), but I want to be able to skip multiple of them together.
What I mean is I would like to change something like this:
ps = fmap (\_ _ a _ _ _ b _ _ -> a+b) ws <*> p1 <*> val <*> ws <*> p2 <*> ws <*> val <*> ws <*> p3
to something like
ps = fmap (\a b -> a+b) ws *> p1 *> val <* ws * p2 * ws *> val <* ws <* p3
Now that doesn't compile, and I'm not sure how to look up if this is even possible to do?