deepseq icon indicating copy to clipboard operation
deepseq copied to clipboard

Box helper to wrap types where WHNF = NF

Open bennofs opened this issue 10 years ago • 3 comments

I'd like a type that can be used to wrap values for which I want WHNF = NF. This is useful for satisfying NFData constraints with criterion for example.

newtype WHNF a = WHNF a
instance NFData (WHNF a) where rnf (WHNF a) = seq a ()

Of course, this data type should be given a better name. Maybe data instead of newtype would also be useful for even more laziness?

bennofs avatar Apr 12 '15 12:04 bennofs

@bennofs btw, wasn't there already some mailing-list discussion about this?

hvr avatar Apr 13 '15 08:04 hvr

I have uploaded a package which does this https://hackage.haskell.org/package/nf though the type is called NF. Eventually we might move it into deepseq but this package will be useful for people who want to use it in older versions of GHC. (We'd like to stabilize it first though.)

ezyang avatar Apr 22 '15 12:04 ezyang

This would be amazing to use with DerivingVia:

data Foo = ...
  deriving NFData via WHNF Foo

no-longer-on-githu-b avatar Feb 21 '19 10:02 no-longer-on-githu-b