deepseq: instance NFData (a -> b)

Michael Walker mike at
Sun May 1 14:58:43 UTC 2016

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
- 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.

I'm +1 to removing this, simply because there are at least three
(including yours) reasonable definitions. If someone wants an NFData
instance for a value which includes functions, they should know exactly
how they want to handle that.

On Sun, 1 May 2016 16:38:07 +0200 (CEST)
Henning Thielemann <lemming at> wrote:

> According to Haddock comments, between deepseq-1.2 and deepseq-1.3 an 
> instance for NFData on functions was introduced without previous 
> discussion. I find this instance pretty problematic since it has no 
> superclasses. The correct instance would be certainly something like
> instance (Enumerate a, NFData b) => NFData (a -> b)
> where Enumerate would be a new class that allows to enumerate all
> values of a type. This would be hardly useful because it is pretty
> inefficient. I'd prefer that the instance is removed, again, or even
> better, be replaced by a non-implementable instance. Alternatively we
> should replace it by a correct implementation with corresponding
> superclasses. If we do the second, then we could still omit the
> Enumerate instance for types where enumeration of all values of the
> type is too expensive.
> I assume that the instance was added to simplify automatic derivation
> of NFData instances. However, I think it would be better if people
> insert custom deepseq implementation for the expected functions then.
> _______________________________________________
> Libraries mailing list
> Libraries at

Michael Walker (
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Libraries mailing list