deepseq:NFData1 class

Henning Thielemann lemming at
Mon Jun 8 18:18:28 UTC 2015

I have the type

    data NonEmpty f a = NonEmpty a (f a)

and want to declare an NFData instance in Haskell 98. With the existing 
NFData class this is not possible because it requires a (NFData (f a)) 
constraint which needs FlexibleContexts. A solution would be an NFData1 
class analogously to the classes in transformers:Data.Functor.Classes:

    class NFData1 f where
       rnf1 :: NFData a => f a -> ()

    instance NFData1 [] where
       rnf1 = rnf

    instance (NFData1 f) => NFData1 (NonEmpty f) where
       rnf1 (NonEmpty x xs) = rnf (x, rnf1 xs)

    instance (NFData1 f, NFData a) => NFData (NonEmpty f a) where
       rnf = rnf1

More information about the Libraries mailing list