[Haskell-cafe] Categories in base
Jean-Philippe Bernardy
jeanphilippe.bernardy at gmail.com
Sun Oct 14 05:02:14 EDT 2007
Hello folks,
Prompted by Ashley's proposal for Category class, I came up with the following
module, which gives a summary of the overloading situation in the base package.
Maybe it can help people find their way through all the available names...
Failing that it surely was fun to come up with. :)
-- JP
{-# OPTIONS -fallow-undecidable-instances #-}
import Prelude ()
class Functor f where
(<$>) :: (a -> b) -> f a -> f b -- a.k.a: fmap, map, liftM
class Functor f => Applicative f where
return :: a -> f a -- a.k.a: Control.Applicative.pure
(<*>) :: f (a -> b) -> f a -> f b -- a.k.a: ap
-- f <$> g = return f <*> g
class Applicative m => Monad m where
(=<<) :: (a -> m b) -> m a -> m b -- a.k.a: flip (>>=)
-- f <*> g = (\h -> (return . h) =<< g) =<< f
class Category c where
id :: c a a
(.) :: c y z -> c x y -> c x z -- a.k.a: (<<<), flip (>>>)
class Category a => Arrow a where
pure :: (b -> c) -> a b c
first :: a b c -> a (b, d) (c, d)
instance Arrow a => Functor (a r) where -- (not defined as such in base, but
ad-hoc)
f <$> g = pure f . g
-- instances for (->)
instance Category (->) where
id = \x -> x
f . g = \x -> f (g x)
instance Arrow (->) where
pure = id
first f = \(b, d) -> (f b, d)
More information about the Haskell-Cafe
mailing list