|
|
|
|
|
by goto11
2392 days ago
|
|
No, you can force operations to execute in linear order without the use of monads, as long as one operation depends on the output of the previous. But you have to be careful not to reuse values. Imagine if the IO operations took an explicit world parameter instead of using a monad: main :: World -> World
main world1 =
let world2 = putStrLn world1 "Hello, what's your name?"
let (world3, name) <- getLine world2
let world4 = putStrLn world3 ("Hey " ++ name ++ ", you rock!")
in world4
The IO operations would be executed in the expected order due to the dependency of the "world" output of the previous operation. Monads not necessary.But if you accidentally used world2 twice then you would split the universe into two timelines. A monad can avoid this issue by hiding the world parameter and passing it on behind the scenes. |
|