Re: [Haskell-cafe] Categories in base

2007-10-14 Thread David Menendez
On 10/14/07, Jean-Philippe Bernardy <[EMAIL PROTECTED]> wrote:
> instance Arrow a => Functor (a r) where  -- (not defined as such in base, but
> ad-hoc)
> f <$> g = pure f . g

Similarly:

instance Arrow a => Applicative (a r) where
return a = pure (const a)
a <*> b = pure (\(f,x) -> f x) . a &&& b

-- 
Dave Menendez <[EMAIL PROTECTED]>

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


[Haskell-cafe] Categories in base

2007-10-14 Thread Jean-Philippe Bernardy
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