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