20-CS-4003-001 | Organization of Programming Languages | Fall 2017 |
---|---|---|
Monads |
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 bTry to use it like this: Prelude> add 3 4and get failure: 'No instance for (Num (m0 b0))'But Prelude> add (Just 3) (Just 4)works fine. Recall: data Maybe a = Nothing | Just aBut Maybe is a Monad also (shown later). |