Proposal #3537: Add missing NFData instances to parallel
Roel van Dijk
vandijk.roel at gmail.com
Wed Sep 23 13:46:58 EDT 2009
> This might be "dirty" but what about this instead?
>
> instance (NFData a) => NFData (Data.IORef.IORef a) where
> rnf r = unsafePerformIO $ modifyIORef r (`using` rnf)
Hmm, I don't know. The question is whether you want to evaluate the
value stored inside of the IORef. I think that any function that
evaluates a value inside of an IORef should be in the IO monad. I
wouldn't expect a function with the type "a -> ()" to be able to "look
into" an IORef.
The reason I made an NFData instance for IORef is for a situation like this:
test :: IO ()
test = do x <- newIORef ()
y <- newIORef ()
let z | hugeConditionalExpression = x
| otherwise = y
rnf z `seq` doSomething
You might want to force z to head normal form to force the evaluation
of the hugeConditionalExpression.
More information about the Libraries
mailing list