[Haskell-cafe] Improving the docs (specifically Data.Foldable)

David Feuer david.feuer at gmail.com
Fri Oct 1 09:35:41 UTC 2021

Right-biased Foldable instances are perfectly reasonable. Just don't expect
fromList, foldr, or foldl' to be good for them.

On Fri, Oct 1, 2021, 5:27 AM Viktor Dukhovni <ietf-dane at dukhovni.org> wrote:

> On Fri, Oct 01, 2021 at 10:05:30AM +0100, Tom Ellis wrote:
> > > But performance may differ radically, and `toList` may diverge for
> > > `snocList` when infinite on the left, though that's a rather
> > > pathological example.
> >
> > If one can't write Foldable-generic functionality in a way that
> > provides some reasonable uniformity of performance over different
> > instances then one wonders what is point of having Foldable as a
> > typeclass at all.  At that point it's just name overloading.
> This is why I was reluctant originally to say anything about
> right-biased structures... They break established expectations.
> I focused mostly on symmetric structures, for which left and right folds
> should perform identically (if instances properly take advantage of the
> symmetry), these are I think practical.  About right-biased structures I
> said:
> https://dnssec-stats.ant.isi.edu/~viktor/haskell/docs/libraries/base/Data-Foldable.html#g:8
>         Finally, in some less common structures (e.g. snoc lists) right
>         to left iterations are cheaper than left to right. Such
>         structures are poor candidates for a Foldable instance, and are
>         perhaps best handled via their type-specific interfaces. If
>         nevertheless a Foldable instance is provided, the material in
>         the sections that follow applies to these also, by replacing
>         each method with one with the opposite associativity (when
>         available) and switching the order of arguments in the fold's
>         operator.
> Concrete suggestions to address any issues in this section (now that the
> title is no longer "Chirality") are welcome (MR 6555).
>     https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6555
> --
>     Viktor.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20211001/87c96c55/attachment-0001.html>

More information about the Haskell-Cafe mailing list