Opened 14 years ago

Last modified 4 years ago

#81 new enhancement

scoping of type variables in class instances

Reported by: Owned by: none
Priority: normal Milestone:
Version: Keywords: scoping type variables
Cc: Meta Owner:
State: discussion Section: N/A or multiple
Related Tickets:


The scoping of type variables in class instances is underspecified. GHC scopes them for the entire instance, Hugs does not.

GHC's approach is more expressive, it is sometimes needed - especially in combination with multi-parameter classes. Example:

class Ping a b where ping:: a->b
newtype A a = A a
instance (Show b,Ping a b) => Show (A a) where
   show (A x) = show (ping x)

This is ambiguous and thus rejected, but we could resolve the ambiguity by annotating 'ping' with its expected type a→b, but that only works if the scoping of the class instance extends to the member definition.


: extends expressiveness, implemented in GHC anyway, was underspecified in Haskell anyway


: very minor: it could break some existing programs as it makes some local functions non-polymorphic, though these would have been badly written

See also:

Change History (5)

comment:1 Changed 14 years ago by ross@…

adopt: maybe
impact: large

comment:2 Changed 14 years ago by ijones

Owner: changed from ijones to none

comment:3 Changed 13 years ago by ijones@…

topic: Class System

comment:4 Changed 4 years ago by Herbert Valerio Riedel


moving non-milestoned many year old legacy tickets out of the way

comment:5 Changed 4 years ago by Herbert Valerio Riedel

Priority: minornormal

Set default priority (as this confuses Trac otherwise)

Note: See TracTickets for help on using tickets.