#3485: "Illegal type synonym family application in instance" error is unnecessary, should be removed

Manuel M T Chakravarty chak at cse.unsw.edu.au
Thu Sep 17 20:56:15 EDT 2009


Ashley Yakeley:
> On Mon, 2009-09-14 at 00:40 +1000, Manuel M T Chakravarty wrote:
>>> I don't see what the problem is. "instance C (Fam Int)" has an
>>> unambiguous, and logically acceptable, meaning to the compiler. Why
>>> do we force the programmer to make an ugly workaround involving
>>> introducing a type variable?
>>
>> I think the proposed change is confusing.  Two instances
>>
>>   instance C (Fam Int)
>>   instance C (Fam Bool)
>>
>> appear to be syntactically distinct, but they semantically overlap.
>> The explicit form
>>
>>   instance (Fam Int ~ famint) => C famint
>>
>> is IMHO much clearer and really not much more verbose.
>
> It's really no different from this
>
>  type Syn a = ()
>
>  instance C (Syn Int)
>  instance C (Syn Bool)

It's quite different.  A type synonym can always be unfolded.  That is  
not the case for a type family; e.g.,

   type family F a
   type instance F [Int] = ...

   instance C (F [a])

Whereas `instance C (Syn Int)' is synonymous to `instance C ()', there  
is no such "normal form" for `instance C (F [a])'.

This is a fundamental difference between type synonyms and type  
families and the reason for most of the restrictions that we impose on  
type families over type synonyms (e.g., synonyms may be partially  
applied in some situations, whereas families may never be applied  
partially).

Manuel



More information about the Glasgow-haskell-bugs mailing list