<div dir="auto">Foldable doesn't have much in the way of interesting laws, really. And I'm not sure how to make the relationships between foldMap, foldr, foldl, foldr', and foldl' clear to beginners. I'll have to think on that a bit. foldMap unifies finite, left-finite, right-finite, and doubly infinite structures, which is a tricky thing to explain to beginners!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 19, 2021, 12:14 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 Sat, Sep 18, 2021 at 09:57:09PM -0400, David Feuer wrote:<br>
<br>
> I'll try to take a look. When writing instances (which I consider a<br>
> beginner-level activity), it's really important to learn to follow the<br>
> laws. While that may just sound like a bunch of theory, it turns out that<br>
> in practice violating typeclass laws leads to seriously unintuitive<br>
> behavior, breaking the expectations users have developed after using many<br>
> instances.<br>
<br>
If that's the intent, the laws for Foldable need a substantially better<br>
explanation that the given equations, which shed very little light on<br>
the actual requirements.<br>
<br>
It would probably be most productive to add new prose explaining the<br>
laws to the "Defining instances" section:<br>
<br>
    <a href="https://dnssec-stats.ant.isi.edu/~viktor/haskell/docs/libraries/base/Data-Foldable.html#g:19" rel="noreferrer noreferrer" target="_blank">https://dnssec-stats.ant.isi.edu/~viktor/haskell/docs/libraries/base/Data-Foldable.html#g:19</a><br>
<br>
and reference the laws also from there, if someone wants the concise<br>
form for QuickCheck property tests or the like.<br>
<br>
I am no longer a novice, and yet would still have a hard time making any<br>
use of the laws as written in constructing instances.  Instead, I'd<br>
ignore the laws and write a natural intuitive instance, and it would<br>
invariably work.  The text in "Definining Instances" aims to help<br>
readers ensure the implementations are reasonably efficient, but<br>
presently does not drag in the laws.<br>
<br>
As the author of the laws section, perhaps you'd be willing to<br>
contribute explanatory prose???<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>