deepseq-bounded-0.5.3: Bounded deepseq, including support for generic deriving

Copyright(c) 2014, Andrew G. Seniuk
LicenseBSD-style (see the LICENSE file)
MaintainerAndrew Seniuk <rasfar@gmail.com>
Stabilityprovisional
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Control.DeepSeq.Bounded.Generics

Description

Support for generic deriving (via Generics.SOP) of NFDataN and NFDataP instances. Also, SOP generic functions implementing Seqable without a class and instances.

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 #-}
{-# LANGUAGE DeriveDataTypeable #-}

import Generics.SOP.TH
import Control.DeepSeq.Bounded ( NFDataN(..), grnfn, NFDataP(..), grnfp )
import Control.DeepSeq.Generics ( NFData(..), genericRnf )
import GHC.Generics ( Generic )    -- for deriving NFData
import Data.Typeable ( Typeable )  -- for name-constrained pattern nodes
import Control.DeepSeq.Bounded ( forcen, forcep )

data TA = A1 TB TA | A2  deriving ( Generic, Typeable )
instance NFData  TA where rnf  = genericRnf
instance NFDataN TA where rnfn = grnfn
instance NFDataP TA where rnfp = grnfp

data TB = B1 Int | B2 TA  deriving ( Generic, Typeable )
instance NFData  TB where rnf  = genericRnf
instance NFDataN TB where rnfn = grnfn
instance NFDataP TB where rnfp = grnfp

deriveGeneric ''TA
deriveGeneric ''TB

main = mainP
mainN = return $! forcen 3          (A1 (B2 undefined) A2) :: IO TA
mainP = return $! forcep ".{.{.}.}" (A1 (B2 undefined) A2) :: IO TA
mainS = return $! force_ Propagate  (A1 (force_ Propagate (B2 undefined)) A2) :: IO TA

Documentation

grnf_ :: Generic a => SeqNodeKind -> a -> () Source

gseq_ :: Generic a => SeqNodeKind -> a -> b -> b Source

gforce_ :: Generic a => SeqNodeKind -> a -> a Source

grnfn :: (Generic a, All2 NFDataN (Code a)) => Int -> a -> () Source

grnfp :: forall a. (Generic a, HasDatatypeInfo a, All2 NFDataP (Code a), NFDataP a) => Pattern -> a -> () Source