Commits

Maxime Henrion  committed 46b0b93

Add an instance for Ratio.

  • Participants
  • Parent commits fd2b29f

Comments (0)

Files changed (1)

File Control/DeepSeq.hs

 
 import Data.Int
 import Data.Word
+import Data.Ratio
 import GHC.Generics
 
 class DeepSeq a where
 instance DeepSeq a => DeepSeq (Maybe a)
 instance (DeepSeq a, DeepSeq b) => DeepSeq (Either a b)
 
+-- We cannot derive an instance for Ratio automatically, because it is an
+-- abstract datatype (it doesn't export its constructors), and doesn't provide
+-- a Generic instance either.
+instance (Integral a, DeepSeq a) => DeepSeq (Ratio a) where
+  deepseq x = deepseq (denominator x) . deepseq (numerator x)
+
 class GDeepSeq f where
   gdeepseq :: f a -> b -> b