Show sources of cost centers in .prof
[ghc.git] / testsuite / tests / generics / GFullyStrict.hs
1 {-# LANGUAGE DefaultSignatures #-}
2 {-# LANGUAGE DeriveAnyClass #-}
3 {-# LANGUAGE DeriveGeneric #-}
4 {-# LANGUAGE FlexibleContexts #-}
5 {-# LANGUAGE FlexibleInstances #-}
6 {-# LANGUAGE ScopedTypeVariables #-}
7 {-# LANGUAGE TypeOperators #-}
8 module Main where
9
10 import Data.Proxy (Proxy(..))
11 import GHC.Generics
12
13 main :: IO ()
14 main = do
15 print (fullyStrict (Proxy :: Proxy (StrictMaybe Bool)))
16 print (fullyStrict (Proxy :: Proxy (Maybe Bool)))
17
18 data StrictMaybe a = StrictNothing | StrictJust !a
19 deriving (FullyStrict, Generic)
20
21 instance FullyStrict Bool
22 instance FullyStrict a => FullyStrict (Maybe a)
23
24 class FullyStrict a where
25 fullyStrict :: proxy a -> Bool
26 default fullyStrict :: (GFullyStrict (Rep a)) => proxy a -> Bool
27 fullyStrict _ = gfullyStrict (Proxy :: Proxy (Rep a p))
28
29 class GFullyStrict f where
30 gfullyStrict :: proxy (f p) -> Bool
31
32 instance GFullyStrict V1 where
33 gfullyStrict _ = True
34
35 instance GFullyStrict U1 where
36 gfullyStrict _ = True
37
38 instance FullyStrict c => GFullyStrict (Rec0 c) where
39 gfullyStrict _ = fullyStrict (Proxy :: Proxy c)
40
41 instance GFullyStrict f => GFullyStrict (D1 c f) where
42 gfullyStrict _ = gfullyStrict (Proxy :: Proxy (f p))
43
44 instance GFullyStrict f => GFullyStrict (C1 c f) where
45 gfullyStrict _ = gfullyStrict (Proxy :: Proxy (f p))
46
47 instance (GFullyStrict f, Selector c) => GFullyStrict (S1 c f) where
48 gfullyStrict _ = gfullyStrict (Proxy :: Proxy (f p))
49 && selDecidedStrictness (undefined :: S1 c f p) /= DecidedLazy
50
51 instance (GFullyStrict f, GFullyStrict g) => GFullyStrict (f :+: g) where
52 gfullyStrict _ =
53 gfullyStrict (Proxy :: Proxy (f p)) && gfullyStrict (Proxy :: Proxy (g p))
54
55 instance (GFullyStrict f, GFullyStrict g) => GFullyStrict (f :*: g) where
56 gfullyStrict _ =
57 gfullyStrict (Proxy :: Proxy (f p)) && gfullyStrict (Proxy :: Proxy (g p))