Lesson 30. Introducing the Monad type class

After reading lesson 30, you’ll be able to

  • Understand the limitations of both Functor and Applicative
  • Use Monad’s (>>=) operator to chain together functions in a context
  • Write IO code without do-notation

You’ve just finished learning about two important type classes, Functor and Applicative. Each has allowed you to perform increasingly powerful computations within a context such as Maybe or IO. Functor allows you to change individual values in a context:

GHCi> (+ 2) <$> Just 3
Just 5

Applicative increases your power by enabling you to use partial application in a context. This, in turn, allows you to use multiple arguments in a context:

GHCi> pure (+) <*> Just 3 <*> Just 2
Just 5

In this lesson, ...

Get Get Programming with Haskell now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.