Proposal: Add a few extra members to Foldable and Traversable classes

Joachim Breitner mail at
Fri Sep 19 20:09:35 UTC 2014


Am Donnerstag, den 18.09.2014, 19:26 -0400 schrieb David Feuer:

> sum, product—may be cached internally in tree nodes for fast update,

I’m a bit doubtful about the real-world impact of having product there,
and probably also sum, besides educational code. Are these so much more
common than other aggregations?

I think if you want to cache something in treenodes for performance, you
should use a suitable data structure there that supports this directly,
instead of hoping that your operation happens to be one of the two
special cases provided by the type class.

Slightly off topic: Wouldn’t it be nice if we would not have to have to
add these methods to provide optimized behavior, but rather have the
user write "sum . toList" or some other idiomatic code (maybe suggested
in the docs), and RULES provided by the container implementer would
reliable replace this with the optimized version. Wouldn’t help in
polymorphic code, but I doubt that much performance critical code is
polymorphic in the container.

But then he could simply provide a sumTree or sumSet or something
else... I should stop mumbling in circles.


Joachim “nomeata” Breitner
  mail at joachim-breitner.de
  Jabber: nomeata at  • GPG-Key: 0xF0FBF51F
  Debian Developer: nomeata at

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the Libraries mailing list