On Fri, Sep 4, 2009 at 12:57 PM, Peter Verswyvelen<[email protected]> 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. Jason _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
