[Haskell-cafe] Type classes and type equality

Jeremy Shaw jeremy.shaw at linspireinc.com
Mon Apr 16 14:18:52 EDT 2007


At Mon, 16 Apr 2007 13:44:13 +0100,
Neil Mitchell wrote:
> 
> Hi,

> So my question is if this is safe? Will the compiler always pick the
> "right one"? Is there a better way to do this?

I noticed that the results can be a bit suprising sometimes. See if
you can predict the answers to these (in ghci):

> same 1 1

> let x = (undefined :: a) in same x x

> f :: a -> Bool
> f a = same a a

> f (undefined :: a)

Here is what ghci says:

*Main> same 1 1
False

*Main> :t 1
1 :: forall t. (Num t) => t

*Main> let x = (undefined :: a) in same x x
False

> f :: a -> Bool
> f a = same a a

*Main> f (undefined :: a)
True

I'm not saying anything is wrong here. Just be careful how you use it
:)

j.


More information about the Haskell-Cafe mailing list