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)





_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to