[Haskell] [Haskell-cafe] Help with polymorphic functions

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu May 8 15:23:53 EDT 2008

Hello Wei,

Thursday, May 8, 2008, 11:10:08 PM, you wrote:

> test :: a -> Int -> a

> shift is defined as "a -> Int -> a"

not exactly ;)  this type signature is given inside class Bits, where
'a' isn't a free variable (as in standalone signature declaration),
but means 'a' from type class header:

class Num a => Bits a where
    shift             :: a -> Int -> a

so, this declaration is equivalent to the following standalone one:

shift :: (Bits a) =>  a -> Int -> a

from the common sense POV, you can't shift *ANY* type 'a', but only
types that belong to the Bits class. so, shift cannot have signature
w/o class, and the same remains true for `test`

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list