deepseq: instance NFData (a -> b)

Boespflug, Mathieu m at
Sun May 1 14:51:45 UTC 2016


This instance doesn't make much sense (to me at least) and is pretty
problematic for apps that use NFData constraints as evidence that
values are ground and fully evaluated (hence don't capture arbitrary
resources). In HaskellR we use NFData constraints to make sure only
fully evaluated ground data escapes the scope of a region. But
functions are not a first-order values. They can leak arbitrary
resources out of the scope of a region.
Mathieu Boespflug
Founder at

On 1 May 2016 at 16:38, 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

More information about the Libraries mailing list