20-CS-4003-001 Organization of Programming Languages Fall 2017
Monads

Lambda calculus, Type theory, Formal semantics, Program analysis

Prev     Next     All lectures           Code

Basics

add x y = do
  x' <- x
  y' <- y
  return (x' + y')
  -   The type of this function is
 add :: (Num b, Monad m) => m b -> m b -> m b
Try to use it like this:
 Prelude> add 3 4
and get failure:
 'No instance for (Num (m0 b0))'
But
 Prelude> add (Just 3) (Just 4)
works fine. Recall:
 data Maybe a = Nothing | Just a
But Maybe is a Monad also (shown later).