[Haskell-cafe] Functional dependenices in class declarations
simonpj at microsoft.com
Thu Aug 11 05:29:55 EDT 2005
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
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
| 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
| to have type parameters which are reachable (184.108.40.206 context of type
| 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
| Any help appreciated!
| Andrew Frank
| Haskell-Cafe mailing list
| Haskell-Cafe at haskell.org
More information about the Haskell-Cafe