[Haskell-cafe] Functional dependenices in class declarations

Simon Peyton-Jones simonpj at microsoft.com
Thu Aug 11 05:29:55 EDT 2005

It's intentional.

Consider this data type declaration

	data B b = MkT (A a b)

Should that be accepted?  The only thing it could possibly mean would be

	data B b = MkT (forall a. A a b)

and I suppose that might possibly be useful.  But in this case you're
also saying that "a" determines "b".  But you can hardly say *forall* a,
if the choice of a determines the (fixed by context) b.

These functional dependencies are tricky things.   Martin Sulzmann and I
wrote a paper about some of the trickiness
(http://research.microsoft.com/%7Esimonpj/Papers/fd-chr/index.htm), and
we're working on a journal version.

My wild guess is that you are trying to convert an O-O idiom into
Haskell, and that's led you to a rather strange program.  Maybe there's
another way to do it.


| -----Original Message-----
| From: haskell-cafe-bounces at haskell.org
[mailto:haskell-cafe-bounces at haskell.org] On Behalf Of
| Frank
| Sent: 08 August 2005 18:17
| To: haskell-cafe at haskell.org
| Subject: [Haskell-cafe] Functional dependenices in class declarations
| In ghc 6.4 (fine work - many gratulations to all who did it!) it is
| permitted
| to have type parameters which are reachable ( context of type
| signatures).
| I tried the following:
| module TypeDependencies where
| class A a b | a -> b
| class (A a b) => B b  where
|     op :: a -> a
| x :: A a b => a -> a
| x = id
| Which compiles fine for the function x, but does complain
| "not in scope: type variable 'a' " for the class (A a b) => B b.
| Is this an intentional restriction that 'reachable' type variables are
| permitted in type definitions, but not in classes? or do I
| something?
| Any help appreciated!
| Andrew Frank
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list