Haskell: some and many [duplicate]
Asked Answered
S

1

12

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...

Sandhurst answered 30/4, 2011 at 11:44 Comment(0)
S
11

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.

Southwick answered 30/4, 2011 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.