[Haskell] Class type constraining?

Benja Fallenstein benja.fallenstein at gmail.com
Fri Jun 22 13:10:30 EDT 2007


2007/6/22, Hugo Pacheco <hpacheco at gmail.com>:
> class Functor f => C f a b | f a -> b where
>    ftest :: f a -> b
>
> I want to write some function
>
> test :: (C f a b) => (a -> b)
> test = ftest . undefined

I'm not sure whether this is what you want, but the "obvious" way to
make this type-check would seem to be to add a functional dependency
and a type signature for 'undefined,' like this:

> class Functor f => C f a b | f a -> b, a b -> f where
>    ftest :: f a -> b
>
> test :: (C f a b) => (a -> b)
> test = ftest . (undefined :: a -> f a)

- Benja


More information about the Haskell mailing list