<div dir="auto">Right-biased Foldable instances are perfectly reasonable. Just don't expect fromList, foldr, or foldl' to be good for them.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 1, 2021, 5:27 AM Viktor Dukhovni <<a href="mailto:ietf-dane@dukhovni.org">ietf-dane@dukhovni.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Oct 01, 2021 at 10:05:30AM +0100, Tom Ellis wrote:<br>
<br>
> > But performance may differ radically, and `toList` may diverge for<br>
> > `snocList` when infinite on the left, though that's a rather<br>
> > pathological example.<br>
> <br>
> If one can't write Foldable-generic functionality in a way that<br>
> provides some reasonable uniformity of performance over different<br>
> instances then one wonders what is point of having Foldable as a<br>
> typeclass at all. At that point it's just name overloading.<br>
<br>
This is why I was reluctant originally to say anything about<br>
right-biased structures... They break established expectations.<br>
<br>
I focused mostly on symmetric structures, for which left and right folds<br>
should perform identically (if instances properly take advantage of the<br>
symmetry), these are I think practical. About right-biased structures I<br>
said:<br>
<br>
<a href="https://dnssec-stats.ant.isi.edu/~viktor/haskell/docs/libraries/base/Data-Foldable.html#g:8" rel="noreferrer noreferrer" target="_blank">https://dnssec-stats.ant.isi.edu/~viktor/haskell/docs/libraries/base/Data-Foldable.html#g:8</a><br>
<br>
Finally, in some less common structures (e.g. snoc lists) right<br>
to left iterations are cheaper than left to right. Such<br>
structures are poor candidates for a Foldable instance, and are<br>
perhaps best handled via their type-specific interfaces. If<br>
nevertheless a Foldable instance is provided, the material in<br>
the sections that follow applies to these also, by replacing<br>
each method with one with the opposite associativity (when<br>
available) and switching the order of arguments in the fold's<br>
operator.<br>
<br>
Concrete suggestions to address any issues in this section (now that the<br>
title is no longer "Chirality") are welcome (MR 6555).<br>
<br>
<a href="https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6555" rel="noreferrer noreferrer" target="_blank">https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6555</a><br>
<br>
-- <br>
Viktor.<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>