Proposal #3537: Add missing NFData instances to parallel

Simon Marlow marlowsd at gmail.com
Thu Sep 24 05:40:43 EDT 2009


On 23/09/2009 18:46, Roel van Dijk wrote:
>> 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.

what's wrong with

instance NFData (Data.IORef.IORef a) where
     rnf r = r `seq` ()

?

Cheers,
	Simon



More information about the Libraries mailing list