Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: some and many [duplicate]

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

like image 248
Landei Avatar asked Apr 30 '11 11:04

Landei


1 Answers

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.

like image 83
fuz Avatar answered Sep 28 '22 15:09

fuz