Edison 1.2rc2

Christian Maeder maeder at tzi.de
Mon Mar 6 10:56:28 EST 2006


Robert Dockins wrote:
> I'm not sure I understand; why do you think that revealing structure  is 
> unsafe?  

I don't want that i.e. equal maps yield different results, just because 
they are internally differently balanced.

> I'm hesitant to give "fold" a longer name because I think it should  be 
> the first fold a programmer reaches for.

I don't aggree. I immediately made it wrong by my own "toList = fold (:) 
[]" and did not even notice foldr or foldl. The fold for efficiency 
should be mainly used by library writers. But users I tell: correctness 
first, efficiency (when needed) later!

> In the fairly common  case 
> where you have a commutative, associative function (eg (+)), you  don't 
> care in what order the function is applied to the elements

These properties are not garuanteed and difficult to track down in the 
few (but severe) cases it's made wrong.

> , and  you 
> have fold f z === foldl f z === foldr f z. 

I see, foldr and foldl are your safe versions! (I think Jean-Philippe 
only has a safe "fold" and misses an unsafe one.)

> In light of this and previous discussions about folds, I think I will  
> be adding a section to the docs about how to chose an appropriate  fold 
> for your application.

At least that plus a warning!

Cheers Christian


More information about the Libraries mailing list