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

Ordering and Combining IO Actions

In the last section, you learned how we could use a function like andThen :: IO a -> (a -> IO b) -> IO b and newIO :: a -> IO a to work with IO in a pure lazy language. Now you’ll have the opportunity to see how functions like this are implemented, and if you follow along with the example you can write them yourself:

 andThen :: ​IO​ a -> (a -> ​IO​ b) -> ​IO​ b
 andThen = (>>=)
 
 newIO :: a -> ​IO​ a
 newIO = return

That might have been a little bit anticlimactic. It turns out that our implementations are actually just providing new names to the existing >>= operator (pronounced bind) and the return function.

If you look at the types of (>>=) and return in ghci you’ll see that they are actually more general ...

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