[Haskell-cafe] Functions of type foo :: f a -> g a

John Meacham john at repetae.net
Tue May 11 14:06:48 EDT 2010


On Tue, May 11, 2010 at 02:01:05PM -0400, Gordon J. Uszkay wrote:
> I would like to build a class that includes a method to move data from one arbitrary functor to another, a natural transformation.   The structures might be more than just functors, but I can start with that.  I ran into some practical issues with resolving the type variables for my multiparameter type class, which I can resolve with functional dependencies.   I can also not isolate the natural transformation from my overall operation, muddling it with the element transformation.  I was wondering if anyone had any words of advice, example  or warning about this kind of function or method in general?
> 
> Class (Functor f, Functor g) => Foo f g a where
>   foo :: f a -> g a
>   bar :: (a->b) -> g a -> g b

A couple points,

  * why is 'a' a member of the type class head? Functors don't care
    about what is stored inside the type, so your class shouldn't either
    if it is a transformer from functor to functor.
  * isn't bar exactly the same as 'fmap' for g?

A better way might be

class (Functor f, Functor g) => FunctorPair f g where
        transformFunctor :: f a -> g a

though, I am not sure what your use is, there isn't an obvious instance
to me, but I don't know what your motivating task is.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/


More information about the Haskell-Cafe mailing list