Re: [Haskell-cafe] Observations about foldM

2009-08-19 Thread Dan Doel
On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: Interestingly, foldM can also be written as a left fold. To see this, note that it is a theorem that foldr f z xs = foldl f z xs as long as f is associative and z is a unit for f. It must also be the case that xs is finite in length,

Re: [Haskell-cafe] Observations about foldM

2009-08-19 Thread Eugene Kirpichov
2009/8/19 Dan Doel dan.d...@gmail.com: On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: Interestingly, foldM can also be written as a left fold. To see this, note that it is a theorem that foldr f z xs = foldl f z xs as long as f is associative and z is a unit for f. This is not

Re: [Haskell-cafe] Observations about foldM

2009-08-19 Thread Daniel Fischer
Am Mittwoch 19 August 2009 16:32:57 schrieb Eugene Kirpichov: 2009/8/19 Dan Doel dan.d...@gmail.com: On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: Interestingly, foldM can also be written as a left fold. To see this, note that it is a theorem that foldr f z xs = foldl f z xs

Re: [Haskell-cafe] Observations about foldM

2009-08-19 Thread Edward Kmett
It is associativity that is required, not commutativity (in addition to the fact that the list is finite). This is why Data.Foldable provides operations for monoids over containers. Monoids just provide you with associativity and a unit, which lets you reparenthesize the fold however you want.

Re: [Haskell-cafe] Observations about foldM

2009-08-19 Thread Eugene Kirpichov
You're right. My bad, indeed. 2009/8/19 Daniel Fischer daniel.is.fisc...@web.de: Am Mittwoch 19 August 2009 16:32:57 schrieb Eugene Kirpichov: 2009/8/19 Dan Doel dan.d...@gmail.com: On Wednesday 19 August 2009 12:14:24 am Jason McCarty wrote: Interestingly, foldM can also be written as a

[Haskell-cafe] Observations about foldM

2009-08-18 Thread Jason McCarty
[This message is literate Haskell] Hi -cafe, I was trying to use Monad.foldM in the State monad recently and ran into some performance issues. They were eventually fixed with seq, but along the way I made some discoveries, which I thought I would share. The Report defines foldM as foldM