
28 Dec
2016
28 Dec
'16
11:24 p.m.
Imants Cekusins wrote:
Yitzchak, how about this:
Prelude Control.Applicative> foldl (<|>) Nothing [Just 1, Nothing, Just 2, Nothing] Just 1 Prelude Control.Applicative> foldr (<|>) Nothing [Just 1, Nothing, Just 2, Nothing] Just 1
? I guess this is due to the nature of (<|>), no?
Yes, you are right. <|> for Maybe satisfies the associative law: (x <|> y) <|> z == x <|> (y <|> z) for all x, y, and z. So it does not matter if you apply it from right to left or from left to right.
Anyway, I'd use asum instead of fold_ for Alternatives.
Agreed. For the actual problem, Ollie is right. I just thought you might be interested in these other concepts that come up from your good thinking. Regards, Yitz