{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE NoMonomorphismRestriction #-} import GHC.Exts (Constraint) type family Parent a class C a b where instance (C (Parent a) b) => C a b where data A1 = A1 data A2 = A2 data A3 = A3 data A4 = A4 type instance Parent A2 = A1 type instance Parent A3 = A2 type instance Parent A4 = A3 data F1 = F1 data F3 = F3 instance C A1 F1 where f _ _ = "F1" instance C A3 F3 where f _ _ = "F3" type family Constraints t a :: Constraint data D t = forall a. (Constraints t a) => D a type instance Constraints A1 a = (C a F1) type instance Constraints A2 a = (C a F1, C a F3) type instance Constraints A3 a = (C a F1, C a F3) type instance Constraints A4 a = (C a F1, C a F3) main = do h = \fn (D x) -> f fn (x :: a)
Standard input is empty
[1 of 1] Compiling Main ( prog.hs, prog.o )
prog.hs:62:18:
Overlapping instances for C a0 b arising from a use of `f'
Matching instances:
instance [overlap ok] C (Parent a) b => C a b
-- Defined at prog.hs:19:10
instance [overlap ok] C A3 F3 -- Defined at prog.hs:37:10
instance [overlap ok] C A1 F1 -- Defined at prog.hs:34:10
(The choice depends on the instantiation of `b, a0'
To pick the first instance above, use -XIncoherentInstances
when compiling the other instance declarations)
In the expression: f fn (x :: a)
In the expression: \ fn (D x) -> f fn (x :: a)
In an equation for `h': h = \ fn (D x) -> f fn (x :: a)
prog.hs:62:24:
Could not deduce (a2 ~ a1)
from the context (Constraints t a)
bound by the type signature for
h :: (Constraints t a) => b -> D t -> String
at prog.hs:61:6-44
or from (Constraints t a1)
bound by a pattern with constructor
D :: forall t a. (Constraints t a) => a -> D t,
in a lambda abstraction
at prog.hs:62:10-12
`a2' is a rigid type variable bound by
an expression type signature: a2 at prog.hs:62:24
`a1' is a rigid type variable bound by
a pattern with constructor
D :: forall t a. (Constraints t a) => a -> D t,
in a lambda abstraction
at prog.hs:62:10
In the second argument of `f', namely `(x :: a)'
In the expression: f fn (x :: a)
In the expression: \ fn (D x) -> f fn (x :: a)
Standard output is empty