
I'm not sure what the more category-theoretic version of Traversable is, though I don't think mapM is actually an instance of a Functor in a Kleisli category in the first place. Consider the Functor laws: mapM return = return mapM (f <=< g) = mapM f <=< mapM g It's easy to show the second law doesn't hold, as in the RHS we have to run all the effects from "mapM g" before any of the effects from "mapM f" can start, while in the LHS the effects will be interleaved. Consider: printId = print a *> pure a mapM (printId <=< printId) [1,2,3] 1 1 2 2 3 3 (mapM printId <=< mapM printId) [1,2,3] 1 2 3 1 2 3 Using traverse/mapM has to hold onto the entire list (thus the need for pipes/conduit). M Farkas-Dyck wrote
Consider this:
class (Category c, Category d) => Functor c d f where map :: c a b -> d (f a) (f b)
Clearly mapM of Traversable is simply map :: Kleisli m a b -> Kleisli m (f a) (f b). But what is traverse? can it be so defined? I am thinking no, as Kleisli composition is not defined in general, but I know very little category theory so I may easily be wrong. _______________________________________________ Haskell-Cafe mailing list
Haskell-Cafe@
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- View this message in context: http://haskell.1045720.n5.nabble.com/General-Functor-and-Traversable-tp58161... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.