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 [3443]
ewrewrew
ewrwwwwww545
43535
435
^CInterrupted.
As you can see, I interrupted the input. How can I use the some
function?
Consider what happens when you try to expand
some [1]
:Here's I've immediately replaced
<|>
with(++)
. Because(++)
is strict in its first argument, you have to evaluatesome_v
before proceeding, but that gets us into an infinite loop.Alternative
is described as a monoid for applicative functors. If I understand correctly,some xs
would be the infinite list of non-empty lists you could create by taking one element fromxs
at a time.and
many xs
would be the infinite list of (possibly empty) lists (essentially, just[]:some xs
.) Because of the strictness of(++)
, though, the result is not computed lazily, so you never actually terminate.