haskell / deepseq

Deep evaluation of data structures
http://hackage.haskell.org/package/deepseq
Other
40 stars 29 forks source link

Add 'Whnf{,1,2}' (or some better name) newtype #78

Open Icelandjack opened 2 years ago

Icelandjack commented 2 years ago
newtype Whnf a = Whnf a
newtype Whnf1 f a = Whnf1 (f a)
newtype Whnf2 bi a b = Whnf2 (bi a b)

instance NFData (Whnf a) where rnf (Whnf a) = a `seq` ()
instance NFData1 (Whnf1 f) where liftRnf _ (Whnf1 as) = as `seq` ()
instance NFData2 (Whnf2 bi) where liftRnf2 _ _ (Whnf2 as) = as `seq` ()
Icelandjack commented 2 years ago

As well as

newtype Rnf1 f a = Rnf1 (f a)

instance (NFData1 f, NFData a) => NFData (Rnf1 f a) where
  rnf (Rnf1 as) = rnf1 as
mixphix commented 1 year ago

You want a newtype instance that will prevent NFData from fully evaluating it?

treeowl commented 1 year ago

I think the nf package may have some stuff like that.