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