[Haskell-cafe] ~ type operator

Henning Thielemann schlepptop at henning-thielemann.de
Sat Jul 2 18:04:12 CEST 2011


On 24.06.2011 11:10, Daniel Fischer wrote:
> On Friday 24 June 2011, 10:26:42, Guy wrote:
>> What does the ~ type operator mean? I've sometimes seen types such as (a
>> ~ b) in error messages, but can't understand what GHC is trying to tell
>> me.
>
> Type equality, (a ~ b) means that a and b are the same type (rather, that
> the compiler can prove they're the same).

This type operator is needed when using type families. With functional 
dependencies you can assert a bijection between types by writing

class C a b | a -> b, b -> a where

but using type functions you have to tell the compiler somehow that one 
type function reverses the mapping of another function. This is where 
(~) is needed. You can use this type operator, when LANGUAGE 
TypeFamilies is enabled.

I assume that the use of (~) in type error messages reflects that GHC's 
type checker is now internally based on type families. There are also 
other circumstances, where GHC uses non-Haskell-98 syntax in its 
messages, e.g. it uses explicit 'forall' quantifiers in error messages 
also if they are disabled in the affected module.



More information about the Haskell-Cafe mailing list