[Haskell-cafe] NFData question

Peter Verswyvelen bugfact at gmail.com
Fri Sep 4 15:57:27 EDT 2009


When ones makes an ADT with data constructors that has strict (and
maybe unpacked) fields,

e.g.

data Vec2 a  = Vec2 {-# UNPACK #-} !a {-# UNPACK #-} !a

how does one define an NFData instance?

Like this?

instance NFData a => NFData (Vec2 a) where
  rnf (Vec2 x y) = rnf x `seq` rnf y

Or is it enough to just do
instance NFData a => NFData (Vec2 a)

since Vec2 is fully strict anyway, so that default rnf implementation will do?

Thanks,
Peter


More information about the Haskell-Cafe mailing list