Show sources of cost centers in .prof
[ghc.git] / testsuite / tests / generics / T10361b.hs
1 {-# LANGUAGE DefaultSignatures #-}
2 {-# LANGUAGE DeriveAnyClass #-}
3 {-# LANGUAGE DeriveGeneric #-}
4 {-# LANGUAGE FlexibleContexts #-}
5 {-# LANGUAGE TypeFamilies #-}
6 {-# LANGUAGE TypeOperators #-}
7 {-# LANGUAGE UndecidableInstances #-}
8
9 module T10361b where
10
11 import GHC.Generics
12
13 ---------------------------------------------------------------------
14 class Convert a where
15 type Result a
16 type instance Result a = GResult (Rep a)
17
18 convert :: a -> Result a
19 default convert :: (Generic a, GConvert (Rep a)) => a -> GResult (Rep a)
20 convert x = gconvert (from x)
21
22 instance Convert Float where
23 type Result Float = Float
24 convert = id
25
26 instance Convert Int where
27 type Result Int = Int
28 convert = id
29
30 ---------------------------------------------------------------------
31 class GConvert f where
32 type GResult f
33 gconvert :: f p -> GResult f
34
35 instance (Convert c) => GConvert (K1 i c) where
36 type GResult (K1 i c) = Result c
37 gconvert (K1 x) = convert x
38
39 instance (GConvert f) => GConvert (M1 i t f) where
40 type GResult (M1 i t f) = GResult f
41 gconvert (M1 x) = gconvert x
42
43 instance (GConvert f, GConvert g) => GConvert (f :*: g) where
44 type GResult (f :*: g) = (GResult f, GResult g)
45 gconvert (x :*: y) = (gconvert x, gconvert y)
46
47 ---------------------------------------------------------------------
48
49 data Data1 = Data1 Int Float
50 deriving (Generic)
51
52 instance Convert Data1
53
54 val :: (Int, Float)
55 val = convert $ Data1 0 0.0
56
57 data Data2 = Data2 Int Float
58 deriving (Generic, Convert)