Ticket #81 (new enhancement)

Opened 6 years ago

Last modified 6 years ago

scoping of type variables in class instances

Reported by: guest Owned by: none
Milestone: Keywords: scoping type variables
Cc: Section:
State:

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

Changed 6 years ago by ross@…

  • impact set to large
  • adopt set to maybe

Changed 6 years ago by ijones

  • owner changed from ijones to none

Changed 6 years ago by ijones@…

  • topic set to Class System
Note: See TracTickets for help on using tickets.