Ticket #81 (new enhancement)

Opened 3 years ago

Last modified 3 years ago

scoping of type variables in class instances

Reported by: guest Assigned to: none
Priority: minor Milestone:
Component: Proposal Version:
Keywords: scoping type variables Cc:
Impact: large Adopt: maybe
Topic: Class System

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

02/03/06 02:55:32 changed by ross@soi.city.ac.uk

  • impact set to large.
  • adopt set to maybe.

02/07/06 16:55:03 changed by ijones

  • owner changed from ijones to none.

03/01/06 15:28:13 changed by ijones@galois.com

  • topic set to Class System.