Skip to Content
Get Programming with Haskell
book

Get Programming with Haskell

by Will Kurt
March 2018
Beginner
616 pages
16h 53m
English
Manning Publications
Content preview from Get Programming with Haskell

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Get Programming with Go

Get Programming with Go

Nathan Youngman, Roger Peppe
Effective Haskell

Effective Haskell

Rebecca Skinner

Publisher Resources

ISBN: 9781617293764Publisher SupportOtherPublisher WebsiteSupplemental ContentErrata PagePurchase Link