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

Gordon J. Uszkay uszkaygj at mcmaster.ca
Thu May 13 15:25:10 EDT 2010


Thank you for all these answers - I learned a lot (especially that the responses come in REALLY quickly, so the digest option is not a good choice).  

I think I need to  rephrase the problem, taking into account what I have learned.  

class (Functor f, Functor g) => Foo f g where
  foo :: f a -> g a

as per John Meacham's suggestion to isolate the transform.  Really, f and g are 'containers' which I want to reshape (and there can be many different re-shapings of g for each f, and different f's can map to the same g, so no fundeps relation holds in general).  I am trying to use classes as an interface description, with this transformation being part of that interface, and also to allow me to experiment with different constraints (e.g. Monad f, Applicative f, etc).

Edward Kmett points out (thank you for that detailed reply!) that there is no canonical foo -- which is a good point, and is indeed the right model --  "natural transformation" was likely a red herring.  What I am trying to do is take a container of data f, and partition it into a structure g as a 'chunking' of that data.  The f container is a potentially infinite stream of data obtained from a generator, and I want to be able to control how much data is extracted, so an eager 'fmap' won't be sufficient (an eager process will be applied to the 'chunks' defined by g).   

I am going to purse the hylomorphism model, but am interested if anyone else has any similar situations, and if using classes to manage the interface is the right strategy.  

Thanks!


Gordon J. Uszkay
uszkaygj at mcmaster.ca





More information about the Haskell-Cafe mailing list