What is the point of many and some functions in Control.Applicative (for Alternative?)

When I load up Control.Applicative in ghci and try, eg many [1,2] or many (Just 1) or some [1,2] or some (Just 1) this never returns. What are the practical uses of these combinators, or for using the Alternative class in general?

On Saturday 03 July 2010 3:57:34 pm Thomas Hartman wrote:
When I load up Control.Applicative in ghci and try, eg
many [1,2] or many (Just 1) or some [1,2] or some (Just 1)
this never returns.
What are the practical uses of these combinators, or for using the Alternative class in general?
import Control.Applicative import Control.Monad import Control.Monad.State type M = StateT [Int] [] pluck :: M Int pluck = do l <- get case l of [] -> empty x:xs -> put xs *> pure x {- *Main> runStateT (many pluck) [1..4] [([1,2,3,4],[]),([1,2,3],[4]),([1,2],[3,4]),([1],[2,3,4]),([],[1,2,3,4])] -} -- Dan

For an applicative parser - many is the same combinator as Parsec's many and some is many1.

On 03/07/2010 21:11, Stephen Tetley wrote:
For an applicative parser - many is the same combinator as Parsec's many and some is many1. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Except that there may be good reason to use a version of many specific to the parser, for example to try to keep the grammar finite and thus easier to analyse, or to play nicely with empty string parses. -- flippa@flippac.org
participants (4)
-
Dan Doel
-
Philippa Cowderoy
-
Stephen Tetley
-
Thomas Hartman