# PROPOSAL: Some more 'Applicative' combinators

Iavor Diatchki iavor.diatchki at gmail.com
Sun Jan 6 21:11:39 EST 2008

```Hello,
Sorry, I should have mentioned the origin of the combinators.  These
are (generalizations of) standard parser combinators, so think of "f
a" in the type as a parser that can construct values of type "a".
With this in mind, it should be more obvious what these combinators
are used for.   For example:
> p `sepBy` sep
is a parser that will return 0 or more occurances of 'p' separated by
'sep'.  Many (all?) parser combinator libraries provide these
functions, so having the generic 'Alternative' interface makes it
easier to write parser that can work with different libraries.
-Iavor

On Jan 6, 2008 3:34 PM, Seth Kurtzberg <seth at cql.com> wrote:
> Can you show some code fragments demonstrating how the combinators are used?  I find it easier to understand the underlying concepts when I have not only the signature and implementation but an example of a typical use.  It doesn't have to be working code, and it might even be pseudo code.  (I'm not sure whether other Haskell folks feel the same way.)
>
>
> On Sun, 6 Jan 2008 13:35:41 -0800
> "Iavor Diatchki" <iavor.diatchki at gmail.com> wrote:
>
> > Hello,
> > I propose that we add the following combinators to the
> > 'Control.Applicative' module:
> >
> > skipMany   :: (Alternative f) => f a -> f ()
> > skipMany p  = skipSome p <|> pure ()
> >
> > skipSome   :: (Alternative f) => f a -> f ()
> > skipSome p  = p *> skipMany p
> >
> > endBy      :: (Alternative f) => f a -> f b -> f [a]
> > endBy p s   = many (p <* s)
> >
> > endBy1     :: (Alternative f) => f a -> f b -> f [a]
> > endBy1 p s  = some (p <* s)
> >
> > sepBy      :: (Alternative f) => f a -> f v -> f [a]
> > sepBy p s   = sepBy1 p s <|> pure []
> >
> > sepBy1     :: (Alternative f) => f a -> f v -> f [a]
> > sepBy1 p s  = (:) <\$> p <*> many (s *> p)
> >
> >
> > Any objections?  Deadline for discussion is 2 weeks from now, which
> > would be the 20th of Jan.
> >
> > -Iavor
> > _______________________________________________
> > Libraries mailing list