Opened 12 years ago

Last modified 2 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:

Description

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.

pros

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

cons

: 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: http://hackage.haskell.org/trac/haskell-prime/wiki/ScopedTypeVariables

Change History (5)

comment:1 Changed 12 years ago by ross@…

adopt: maybe
impact: large

comment:2 Changed 12 years ago by ijones

Owner: changed from ijones to none

comment:3 Changed 12 years ago by ijones@…

topic: Class System

comment:4 Changed 2 years ago by Herbert Valerio Riedel

Milestone:

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

comment:5 Changed 2 years ago by Herbert Valerio Riedel

Priority: minornormal

Set default priority (as this confuses Trac otherwise)

Note: See TracTickets for help on using tickets.