deepseq icon indicating copy to clipboard operation
deepseq copied to clipboard

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

Open Icelandjack opened this issue 3 years ago • 3 comments

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 avatar Mar 23 '22 23:03 Icelandjack

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

Icelandjack avatar Mar 23 '22 23:03 Icelandjack

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

mixphix avatar Jan 29 '23 00:01 mixphix

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

treeowl avatar Apr 03 '23 23:04 treeowl