O'Reilly logo

Get Programming with Haskell by Will Kurt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 32. The list monad and list comprehensions

After reading lesson 32, you’ll be able to

  • Use do-notation to generate lists
  • Filter results in do-notation by using guard
  • Further simplify do-notation with list comprehensions

At the end of the preceding lesson, you saw that List is an instance of Monad. You saw only a simple example of using List as a Monad to process a list of candidates.

Listing 32.1. The assessCandidateList function from the previous lesson
assessCandidateList :: [Candidate] -> [String]
assessCandidateList candidates = do
   candidate <- candidates                        1
   let passed = viable candidate                  2
   let statement = if passed                      3
                   then "passed"
                   else "failed"
   return statement                               4
  • 1 By using <- , you’re able to treat your list of candidates like ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required