[Haskell-cafe] NFData question

Jason Dagit dagit at codersbase.com
Fri Sep 4 16:04:44 EDT 2009

On Fri, Sep 4, 2009 at 12:57 PM, Peter Verswyvelen<bugfact at gmail.com> wrote:
> 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

I think  you need your definition here because if you had:
Vec2 (String, String)

I think the declaration of Vec2 just ensures that the tuple is
constructed.  But to ensure that the strings are evaluated, you need
to recursively call rnf (I think).

That's my understanding, but I could be wrong.


More information about the Haskell-Cafe mailing list