#4189: Add (<.>) operator (generalizing (.) to Functor)

Dan Doel dan.doel at gmail.com
Mon Aug 2 09:59:24 EDT 2010


On Monday 02 August 2010 9:30:12 am Maciej Marcin Piechotka wrote:
> As self-corrected (<=<), (.) and (>=>) so exactly the operators it is
> suppose to be used with.

  (f &&& g) x = (f x, g x)

  (f *** g) (x, y) = (f x, g y)

  (f ||| g) (Left  x) = f x
  (f ||| g) (Right y) = g y

  (f +++ g) (Left  x) = Left (f x)
  (f +++ g) (Right y) = Right (g y)

They may be Arrow-related functions, and so not all instances behave this way. 
But (->) is an Arrow after all. The point of all of these is that we don't 
conceptualize them as "three parameter functions." They are two parameter 
functions, with the two parameters being functions, and the result being a 
function. And when thought of in that way, they can be nice ways of 
structuring programs, by building up larger functions out of smaller 
components.

I can even go on. :)

  (m >>= f) r = f (m r) r -- reader monad

  (m >>= f) s = let (s', a) = m s in f a s' -- state monad

  (m >>= f) k = m $ \a -> f a k -- cont monad

Those (except the first) get obscured by newtypes, though.

-- Dan


More information about the Libraries mailing list