
Don't use the
data (context) => type = constructors syntax, it doesn't do what you want.
All it does is add the context to the constructor B while not providing it to any of the functions that use it. A better solution is
data Bar a = forall b. Foo a b => B a b
or, equivalently, using GADT syntax:
data Bar a where B :: Foo a b => a -> b -> Bar a
Pattern matching on B will bring the Foo a b context into scope which will fix b via the functional dependency. However, I prefer this way of solving the problem:
class Foo a where type FooVal a ...
data Bar a = B a (FooVal a)
-- ryan
2009/2/16 Louis Wasserman
Is there a way of exploiting functional dependencies in the following fashion?
class Foo a b | a -> b where...
data Foo a b => Bar a = B a b
This is not ambiguous, because the functional dependency ensures a unique b if one exists. Can this be done without mentioning b as a type variable in Bar?
Louis Wasserman wasserman.louis@gmail.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe