summaryrefslogtreecommitdiff
path: root/testsuite/tests/generics/T11358.hs
blob: 8f52d5ce68401417962c8d0787c276ed0e73bf4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
module Main (main) where

import GHC.Generics

infixr 1 `T`
data T a = T a a deriving Generic
instance HasFixity (T a)

data I a = a `I` a deriving Generic
instance HasFixity (I a)

class HasFixity a where
  fixity :: a -> Fixity
  default fixity :: (Generic a, GHasFixity (Rep a)) => a -> Fixity
  fixity = gfixity . from

class GHasFixity f where
  gfixity :: f a -> Fixity

instance GHasFixity f => GHasFixity (D1 d f) where
  gfixity (M1 x) = gfixity x

instance Constructor c => GHasFixity (C1 c f) where
  gfixity c = conFixity c

main :: IO ()
main = do
  putStrLn $ show (fixity (T "a" "b")) ++ ", " ++ show (fixity ("a" `I` "b"))