
14 Jan
2015
14 Jan
'15
3:47 a.m.
Richard Eisenberg wrote:
`~` is simply equality on types. The constraint `a ~ b` means that `a` is the same type as `b`. We could have spelled it `=` if that weren't used elsewhere. Before `~` was added to GHC, it might have been implemented like this:
class Equals a b | a -> b, b -> a instance Equals x x -- no other instances!
Actually, `~' has been implemented, back in 2004, and the implementation quite a bit more involved than the above (although still taking a couple of lines). The `~' constrain was called TypeCast back then, and there is a page about it explaining the benefits and peculiarities of the implementation. http://okmij.org/ftp/Haskell/typecast.html Perhaps the many examples of TypeCast make it less mysterious.