Search code examples
haskellapplicativecombinatorsalternative-functorsome-and-many

Haskell: some and many


What are some and many in Control.Applicative.Alternative good for? If I write something like some $ Just 42, it seems to cause infinite recursion, which seems not very useful...


Solution

  • They make sense when used as parser combinators.

    some means that the parser is applied as many times as possible, but at least once.

    many is similar, but allows for no parse as well, returning [] in such case instead of failing.

    In case of Maybe, Just ... never "fails", thus your parser some $ Just 42 loops.