[Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

Ryan Ingram ryani.spam at gmail.com
Mon Feb 16 14:52:27 EST 2009


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 <wasserman.louis at gmail.com>:
> 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 at gmail.com
>
>
> _______________________________________________
> 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