[Haskell-cafe] Haskell reference documentation, laws first or laws last?

Viktor Dukhovni ietf-dane at dukhovni.org
Sun Sep 19 04:12:09 UTC 2021

On Sat, Sep 18, 2021 at 09:57:09PM -0400, David Feuer wrote:

> I'll try to take a look. When writing instances (which I consider a
> beginner-level activity), it's really important to learn to follow the
> laws. While that may just sound like a bunch of theory, it turns out that
> in practice violating typeclass laws leads to seriously unintuitive
> behavior, breaking the expectations users have developed after using many
> instances.

If that's the intent, the laws for Foldable need a substantially better
explanation that the given equations, which shed very little light on
the actual requirements.

It would probably be most productive to add new prose explaining the
laws to the "Defining instances" section:


and reference the laws also from there, if someone wants the concise
form for QuickCheck property tests or the like.

I am no longer a novice, and yet would still have a hard time making any
use of the laws as written in constructing instances.  Instead, I'd
ignore the laws and write a natural intuitive instance, and it would
invariably work.  The text in "Definining Instances" aims to help
readers ensure the implementations are reasonably efficient, but
presently does not drag in the laws.

As the author of the laws section, perhaps you'd be willing to
contribute explanatory prose???


More information about the Haskell-Cafe mailing list