Why couldn't the compiler match type 'a == a' to 'True' for a type family?

Is there a reason why this code is not compiled:

type family Foo ab :: Bool where Foo ab = a == b foo :: Foo ab ~ True => Proxy a -> Proxy b foo _ = Proxy bar :: Proxy a -> Proxy a bar = foo 

with an error:

 Couldn't match type 'a == a' with ''True' Expected type: 'True Actual type: Foo aa 

but if I changed the definition of a family of families to

 type family Foo ab :: Bool where Foo aa = True Foo ab = False 

did it compile well?

(GHC-7.10.3)

+8
haskell type-families data-kinds
source share
1 answer

Due to a complete working example request from Daniel Wagner, I found the answer.

At the end of the example:

 {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE PolyKinds #-} module Test where import Data.Type.Equality(type (==)) import Data.Proxy(Proxy(..)) type family Foo ab :: Bool where Foo ab = a == b foo :: Foo ab ~ True => Proxy a -> Proxy b foo _ = Proxy bar :: Proxy a -> Proxy a bar = foo 

The problem here is in PolyKinds pragma. It works well without him. I probably need this to write

 bar :: Proxy (a :: *) -> Proxy a 

and everything is going well.

Now the reason is clear. The type family ( == ) does not have poly-like instances (the details explain why such instances are not provided here ), so we cannot reduce all the equalities. Therefore, we need to specify the view.

+9
source share

All Articles