[Haskell-beginners] Alternative

Imants Cekusins imantc at gmail.com
Wed Dec 28 22:14:18 UTC 2016


thank you Tony and Yitzchak.

I may understand it one day ;)

it is important to understand it alright. I remember spending half a day
over unexpected (for me) results of recursive functions that contained
folds. In the end I settled for TChan - a queue with predictable behaviour
(my view of it - not necessarily correct).


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?

Anyway, I'd use asum instead of fold_ for Alternatives.


for non-Alternative cases, Erlang analogy seems to be a useful rule of
thumb for foldl & foldr over shorter lists .

After all, what matters most is what results to expect. *foldl* and *foldr*
may yield different results for the same list & similar processing fn (save
for different arg order).
‚Äč
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161228/088cac3c/attachment.html>


More information about the Beginners mailing list