flexible contexts and context reduction

Simon Peyton-Jones simonpj at microsoft.com
Thu Mar 27 05:14:52 EDT 2008


| Well, Ord Foo doesn't hold, does it? So Ord (a, b) isn't equivalent to (Ord a, Ord b).

Indeed not.  But that was not what Tom was suggesting (although he was not very explicit).  What he meant was this:

If you write the instance
        instance Theta => Foo (T a b) where ...
where Theta is an arbitrary context, then, given a dictionary for (Foo (T a b)), you can get dictionaries for each constraint in Theta.  Or in logic

        Theta <=> Foo (T a b)

In your example, Theta is empty.

If you'd written
        instance (Show a, Ix b) => Ord (a,b)
then you could get a Show a and Ix b dictionaries from an Ord (a,b) dictionary.  (But not an Ord a or Ord b one.)

S
|
| Ganesh
|
| -----Original Message-----
| From: Simon Peyton-Jones [mailto:simonpj at microsoft.com]
| Sent: 27 March 2008 09:05
| To: Sittampalam, Ganesh; 'Tom Schrijvers'; Ganesh Sittampalam
| Cc: glasgow-haskell-users at haskell.org; Martin Sulzmann
| Subject: RE: flexible contexts and context reduction
|
| Why "unfortunately"? Looks fine to me.
|
| Simon
|
| |
| | Unfortunately, GHC accepts the following:
| |
| | {-# LANGUAGE FlexibleInstances #-}
| | module Foo2 where
| |
| | data Foo = Foo
| |   deriving Eq
| |
| | instance Ord (Foo, Foo) where
| |   (Foo, Foo) < (Foo, Foo) = False
|
| ==============================================================================
| Please access the attached hyperlink for an important electronic communications disclaimer:
|
| http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
| ==============================================================================



More information about the Glasgow-haskell-users mailing list