Search code examples
haskellfunctional-programmingcategory-theory

Confusing map function definition in Wadler's paper


Can someone please help me understand this map definition in Professor Wadler's original paper Monads for Functional Programming (Haskell).

map :: (a → b) →(M a →M b)     
map  f m =m >= λa.unit(f a)

I understand why it is declared as a morphism from f::a -> b to g::Ma -> Mb. Why is it confusingly defined as seemingly taking 2 args f and m. m is a computation ( function with side effects) that I assume can be defined as data or type.


Solution

  • A definition of the form

    foo x y z = bar
    

    is equivalent to all of the following ones

    foo x y = \z -> bar
    foo x = \y z -> bar
    foo = \x y z -> bar
    

    Hence, the posted code could also be written as

    map :: (a → b) → (M a → M b)     
    map f = \m -> m >= \a -> unit (f a)
    -- which is parsed as
    -- map f = \m -> (m >= (\a -> (unit (f a))))
    

    The above indeed emphasizes that map maps functions to functions, and is arguably clearer. However, it is a bit more verbose, so it is common in Haskell to move the arguments to the left side of = as much as possible.