July 2023
Intermediate to advanced
670 pages
17h 13m
English
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 ...