ghc fails to find the right instance

Claus Reinke claus.reinke at talk21.com
Tue Apr 1 15:11:52 EDT 2008


|But I can’t follow your explanation completely. When I use the variant
|with Integer, ghc will not use the instance because (1::Num a => a) is
|too general.
|
|But why does it use the Integral i-Instance in the working variant?
|(1::Num a=> a) is also more general than (1::Integral i => i), isn’t it?

because instance selection does not take instance contexts
into account (a frequent source of feature requests;-):

http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#instance-overlap

so, the match is against 'i', and the 'Integral i' is added
to the constraints needing proof *after* that instance
has been chosen.

claus




More information about the Glasgow-haskell-users mailing list