Copyright | (c) 2014, Andrew G. Seniuk |
---|---|
License | BSD-style (see the LICENSE file) |
Maintainer | Andrew Seniuk <rasfar@gmail.com> |
Stability | provisional |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Support for generic deriving (via Generics.SOP) of NFDataN
instances.
NFDataN
does not have any superclasses.
It is also possible to derive instances using Generics
, which
avoids SOP and TH, but if you plan to use NFDataP
then SOP is required.
(SOP can be used without TH if necessary; the interested reader is
referred to SOP documentation.)
This metaboilerplate is standard for using the generic deriving facilities of GHC.Generics and Generics.SOP. Consider seqaid for a turnkey solution.
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DeriveGeneric #-} import Generics.SOP.TH import Control.DeepSeq.Bounded ( NFDataN(..), grnfn ) import GHC.Generics ( Generic ) import Control.DeepSeq.Bounded ( forcen ) data TA = A1 TB TA | A2 deriving ( Generic ) instance NFDataN TA where rnfn = grnfn data TB = B1 Int | B2 TA deriving ( Generic ) instance NFDataN TB where rnfn = grnfn deriveGeneric ''TA deriveGeneric ''TB main = return $! forcen 3 (A1 (B2 undefined) A2)