deepseq: instance NFData (a -> b)

Dan Doel dan.doel at
Sun May 1 18:12:13 UTC 2016

On Sun, May 1, 2016 at 10:58 AM, Michael Walker <mike at> wrote:
> It depends on what you mean when you say a function is in normal form.
> Unfortunately the instance doesn't capture either of the definitions
> that immediately come to my mind:
> - All values it returns are in normal form? This requires an NFData b
>   constraint.

Even when talking about term rewriting, reducing an application of two
normal forms does not necessarily yield a normal form directly.

> - The body of the function is in normal form? This requires HNF, which
>   we don't have in Haskell. I guess the current instance is going for
>   this, but approximates HNF with WHNF.

Requiring the body to be in normal form would actually be normal form.
Head normal form is actually a weaker condition, where the body must
not be a redex. But the distinction is rather academic, because
neither of these can easily be achieved in GHC.

Anyhow, I would suggest not getting hung up on what 'normal form'
means, because it is actually just a bad name for what is going on
once functions are involved. Really, that's why the class is named
`NFData` in my mind, because talking about what it does as being the
'normal form' only really makes sense when you're talking about pure,
sum-of-products algebraic data, and functions are not that.

The more important question is, what is desirable behavior, and why?
Why would enumerating all possible results of a function and deep
seqing them be the desired behavior of deep seqing a function? It
doesn't necessarily, for instance, have the sort of, 'pull everything
into memory to free another scarce resource,' effect mentioned,
because functions don't work that way.

I would guess that the main argument for this behavior is to say that
it is the only 'allowed' behavior, but, being useless, it should just
be removed. But it would be better to argue that the instance should
be removed directly.

-- Dan

More information about the Libraries mailing list