Skip to Content
Effective Haskell
book

Effective Haskell

by Rebecca Skinner
July 2023
Intermediate to advanced
670 pages
17h 13m
English
Pragmatic Bookshelf
Content preview from Effective Haskell

Independently Sequencing IO Actions

The >>= function gives you a way to pass a value through some functions while making sure that they are executed in some specific sequence, but sometimes you might find that you don’t actually care about the value.

Imagine that you have several functions that have the type IO (), and you wanted to run them in order. As an example, say we wanted to print several different lines of text to the screen. At first we might try to use >>= to do this, but we’ll get an error:

 λ putStrLn "hello world" >>= putStrLn "nice to meet you" >>= putStrLn "goodbye"
 
 <interactive>:16:28: error:
  • Couldn't match expected type ‘() -> IO a0’
  with actual type ‘IO ()’
  • Possible cause: ‘putStrLn’ is applied to too many arguments ...
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

Grokking Functional Programming

Grokking Functional Programming

Michal Plachta
Grokking Algorithms

Grokking Algorithms

Aditya Bhargava
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols

Publisher Resources

ISBN: 9798888650400Errata Page