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

f1 x = if (x == "hello") then 2 
       else 10

f2 x = if (x == 'a') then 4 else 9

add x y = do
  x' <- f1 x
  y' <- f2 y
  return (x' + y')
  -   The same example as in the previous slide but with f1 and f2 added. This loads but
 Prelude> add "hello" 'b' 
fails with this:
 'No instance for (Num (m0 b0))' 
The type of add is now
 add :: (Num (m b), Num b, Monad m) => [Char] -> Char -> m b