instance declaration troubles
Simon Peyton-Jones
simonpj@microsoft.com
Fri, 7 Mar 2003 13:24:50 -0000
Argh. The documentation is out of date, or rather, inconsistent.
In Section 7.3.4 you'll see that GHC -fglasgow-exts lifts the
restriction that class methods must not constrain only the class type
variable.
I'll fix 7.3.5.2, which you are quoting.
Simon
| -----Original Message-----
| From: Hal Daume III [mailto:hdaume@ISI.EDU]
| Sent: 07 March 2003 03:16
| To: Nick Name
| Cc: haskell-cafe@haskell.org
| Subject: Re: instance declaration troubles
|=20
| From the GHC docs:
|=20
| In the signature of a class operation, every constraint must mention
at
| least one type variable that is not a class type variable. Thus:
|=20
| class Collection c a where
| mapC :: Collection c b =3D> (a->b) -> c a -> c b
|=20
| is OK because the constraint (Collection a b) mentions b, even though
it
| also mentions the class variable a. On the other hand:
|=20
| class C a where
| op :: Eq a =3D> (a,b) -> (a,b)
|=20
| is not OK because the constraint (Eq a) mentions on the class type
| variable a, but not b. However, any such example is easily fixed by
moving
| the offending context up to the superclass context:
|=20
| class Eq a =3D> C a where
| op ::(a,b) -> (a,b)
|=20
| A yet more relaxed rule would allow the context of a class-op
signature to
| mention only class type variables. However, that conflicts with Rule
| 1(b) for types above.
|=20
| --
| Hal Daume III | hdaume@isi.edu
| "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
|=20
| On Fri, 7 Mar 2003, Nick Name wrote:
|=20
| >
| > I want to declare the following:
| >
| > class Get a where
| > ls :: a b -> IO [b]
| > mk :: IO [b] -> a b
| >
| > instance (Get a) =3D> Functor a where
| > fmap f x =3D mk (ls x >>=3D return . map f)
| >
| >
| > But to have ghc type everything, I have to turn on "-fglasgow-exts
| > -fallow-undecidable-instances -fallow-overlapping-instances".
| >
| > Is there a clean way to state that all types in my type class are
also
| > in the "Functor" type class?
| >
| > If not, what is the problem?
| >
| > Vincenzo
| > _______________________________________________
| > Haskell-Cafe mailing list
| > Haskell-Cafe@haskell.org
| > http://www.haskell.org/mailman/listinfo/haskell-cafe
| >
|=20
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe@haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe