Ticket #3772: T.hs

File T.hs, 501 bytes (added by rl, 4 years ago)
Line 
1module T where
2
3class DeepSeq a where
4  deepSeq :: a -> b -> b
5
6instance DeepSeq Double where
7  deepSeq = seq
8
9instance DeepSeq a => DeepSeq [a] where
10  {-# INLINE deepSeq #-}
11  deepSeq xs b = foldr deepSeq b xs
12
13class DeepSeq a => C a where
14  gen :: Int -> a
15
16instance C Double where
17  gen = fromIntegral
18
19instance C a => C [a] where
20  gen n = replicate n (gen n)
21
22data B a b = B (a -> b) a
23
24apply :: (C a, DeepSeq b) => Int -> (a -> b) -> ()
25{-# INLINE apply #-}
26apply n f = f (gen n) `deepSeq` ()
27