Check that a default type signature aligns with the non-default signature
[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
20 :: (Generic a, GConvert (Rep a), Result a ~ GResult (Rep a))
21 => a -> Result a
22 convert x = gconvert (from x)
23
24 instance Convert Float where
25 type Result Float = Float
26 convert = id
27
28 instance Convert Int where
29 type Result Int = Int
30 convert = id
31
32 ---------------------------------------------------------------------
33 class GConvert f where
34 type GResult f
35 gconvert :: f p -> GResult f
36
37 instance (Convert c) => GConvert (K1 i c) where
38 type GResult (K1 i c) = Result c
39 gconvert (K1 x) = convert x
40
41 instance (GConvert f) => GConvert (M1 i t f) where
42 type GResult (M1 i t f) = GResult f
43 gconvert (M1 x) = gconvert x
44
45 instance (GConvert f, GConvert g) => GConvert (f :*: g) where
46 type GResult (f :*: g) = (GResult f, GResult g)
47 gconvert (x :*: y) = (gconvert x, gconvert y)
48
49 ---------------------------------------------------------------------
50
51 data Data1 = Data1 Int Float
52 deriving (Generic)
53
54 instance Convert Data1
55
56 val :: (Int, Float)
57 val = convert $ Data1 0 0.0
58
59 data Data2 = Data2 Int Float
60 deriving (Generic, Convert)