Questions tagged [some-and-many]

`some` and `many` are functions in Haskell's `Alternative` type class.

some and many are functions in Haskell's Alternative type class.

some returns one or more, many -- 0 or more results in a list, collected from performing the same computation over and over by the maximal munch rule. For this to make sense, some state passing (and alteration) must take place reducing the domain of possibilities somehow, otherwise it will repeat ad infinitum. State passing is closely related to parsing.

10 questions
53
votes
5 answers

What are Alternative's "some" and "many" useful for?

Alternative, an extension of Applicative, declares empty, <|> and these two functions: One or more: some :: f a -> f [a] Zero or more: many :: f a -> f [a] If defined, some and many should be the least solutions of the equations: some v = (:) <$>…
Petr
  • 62,528
  • 13
  • 153
  • 317
22
votes
2 answers

'some' and 'many' functions from the 'Alternative' type class

What are the functions some and many in the Alternative type class useful for? Docs provide a recursive definition which I was unable to comprehend.
14
votes
1 answer

Can the continuation monad transformer be given an Alternative instance with some and many?

We can define the continuation monad transformer as data Cont r m a = Cont {run :: (a -> m r) -> m r} We can give Cont r m an Alternative instance if m is a member of Alternative via empty = Cont $ \f -> empty ca <|> cb = Cont $ \f -> run ca f <|>…
12
votes
1 answer

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...
Landei
  • 54,104
  • 13
  • 100
  • 195
4
votes
1 answer

why Alternative's some and many are infinite recursive functions in haskell

I was looking at Alternative typeclass in haskell and I was playing with it in ghci when I issued this some (Just 2) It hanged, I looked in the source code of Alternative, Alternative's some and many default definition is this : some :: f a -> f…
niceman
  • 2,653
  • 29
  • 57
3
votes
0 answers

What do the "some" and "many" functions of Alternative do?

I'm working through Write You a Haskell, and I'm on the part where he implements "Nanoparsec", a Haskell parser from first principles. I'm getting stuck on the Alternative instance of the parser, specifically the some and many…
dopatraman
  • 13,416
  • 29
  • 90
  • 154
3
votes
1 answer

Haskell - some, many implementation

In the article: "Write you a Haskell" (page 34) the following interpretation of "some" and "many" is given: Derived automatically from the Alternative typeclass definition are the many and some functions. many takes a single function argument…
coder_bro
  • 10,503
  • 13
  • 56
  • 88
2
votes
1 answer

How to use the function `some`?

I would like to use the some function from Alternative http://hackage.haskell.org/package/base-4.12.0.0/docs/src/GHC.Base.html#some. I've tried: *MyParser Data.Attoparsec.Text Control.Applicative Data.Text> some…
softshipper
  • 32,463
  • 51
  • 192
  • 400
2
votes
1 answer

What is the meaning of the definitions for the "some" and "many" functions in the Haskell Alternative

I've been looking to write a lexer in Haskell and stumbled upon these functions. If defined, some and many should be the least solutions of the equations: some v = (:) <$> v <*> many v many v = some v <|> pure [] I get that the (:) in some gets…
northlane
  • 293
  • 1
  • 9
1
vote
0 answers

Infinite loop when calling many on custom Parser

I'm loosely following Stephen Diehl's Write you a Haskell for implementing my own parser. However, I'm stuck at a point where calls to many and some will go into an infinite loop. I have pinpointed the loop to my parser's fmap function using trace,…
MikaelF
  • 3,518
  • 4
  • 20
  • 33