In the case of both Maybe and [], an action that succeeds once will always succeed. Parsers, other state transformers, and IO don't work like that, however. I'm not sure where else these apply.
On Sat, Sep 19, 2015 at 06:13:18PM +0100, Tom Ellis wrote:
> On Sat, Sep 19, 2015 at 01:25:00AM -0400, David Feuer wrote:
> > It kind of seems like there should be fold-like things to match some and
> > many.
> >
> > foldrAlt :: Alternative f => (a -> b -> b) -> b -> f a -> f b
> > foldrAlt c n m = foldr1Alt c n m <|> pure n
> >
> > foldr1Alt :: Alternative f => (a -> b -> b) -> b -> f a -> f b
> > foldr1Alt c n m = c <$> m <*> foldrAlt c n m
> [...]
>
> An Alternative allows list-like behaviour when it comes to *construction*,
> but offers no operation analogous to pattern-matching and therefore doesn't
> allow you to look inside it or do any sort of *destruction*.
>
> I tried foldrAlt and it looped forever, as I expected. I also expect the
> others to loop forever.
I now understand this can work for some Alternatives. The operational reading
is
1. Try to read an a
2. If it fails, return the b
3. If it succeeds, update the b
4. Go to 1
However, since it doesn't work even for an Alternative as simple as Maybe
it's worth thinking about what class of Alternatives we really want it to
apply to.
Tom
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe