The private type family is not working properly

A few hours ago, I built the GHC HEAD to experiment with the new shiny closed family types.

{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-} type family C ab where C a [a] = [a] C aa = [a] 

Now I'm trying to use C to use:

 class Combine ab where combine :: a -> b -> C ab instance Combine a [a] where combine ab = a : b instance Combine aa where combine ab = [a, b] 

Which leads to this error:

 Couldn't match expected type ‛C a a' with actual type ‛[a]' ... In the expression: [a, b] In an equation for ‛combine': combine ab = [a, b] In the instance declaration for ‛Combine a a' 

It seems to me that the second equation is different from the first ( [a] a cannot be simplified to aa , regardless of what a ), so why doesn't it compile?

+7
haskell type-families
source share
1 answer

I looked through the mail archives a bit. Unfortunately, it seems that a ~ b does not exclude the possibility that a ~ [b] , because such stupidity is accepted:

 type family G = [G] 

As a result, in the case of Combine aa , when we call C aa to find out what the return type should be, no reduction is possible: because we don’t know anything about a , we don’t know, t know yet whether to choose branch C aa or C a [a] C type families, and we cannot make any abbreviations so far.

More detailed information in this topic of the mailing list , in which there are many follow-up actions (which seem to be difficult to find from the previous link) next month archive per thread . The whole situation really seems a little strange to me, although I'm not sure what would be the best solution.

+7
source share

All Articles