I'm having some trouble with the NFData class in Control.DeepSeq. I'd like my type to implement its Functor fmap in parallel using the Control.Parallel.Strategies module. For example, in the following code, I get an error starting "Could not deduce (NFData b)...". If I use rseq instead of rdeepseq there is no problem, however I would like to experiment with rdeepseq. I have GHC 6.12.3 running under Ubuntu 11.04.
module Main where
import Control.Parallel.Strategies
import Control.DeepSeq
data Foo a = Foo Int [a]
deriving (Show,Eq)
instance Functor Foo where
fmap f (Foo i xs) = Foo i (map f xs `using` parList rdeepseq)
Sorry, that's not possible. If you look at your fmap you can see that it uses rdeepseq which needs the type a in the list inside Foo to be in class NFData. But there is simply nowhere to attach this constraint, because that type variable is not mentioned anywhere in the instance declaration.
There are various workarounds using non-standard versions of Functor, but none of them are pleasant.
Have a look at Haskell Type Constraints Unleashed for a suggested solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With