Version 4 (modified by chak@…, 8 years ago) (diff)


Class Method Types

Brief Explanation

In Haskell 98, s4.3.1, the signatures of methods in a class may contain constraints, but these constraints must not mention the argument of the type class. The following is illegal:

class Foo a where
    op :: Num a => a -> a -> a

The motivation was perhaps that without such constraints, class dictionaries could be represented as records with PolymorphicComponents.

However this restriction is not implemented by Hugs, following a suggestion of Mark Jones in Typing Haskell in Haskell, and can be turned off in GHC with -fglasgow-exts.


  • In the absence of this restriction, a type-preserving translation of a type system including either AssociatedTypes or FunctionalDependencies becomes much more difficult (see Section 4.3.4 of Associated Types with Class, POPL'05). Even if we adopt neither of these two type system features for Haskell', we will impact future directions of Haskell.


relax restriction on signatures of class methods