2 ms·
Yep[0], and if you really wanted to, you could use that syntax to express the monadic interface: putStrLn :: TheWorld -> String -> (TheWorld, ()) main ::
by jmillikin 4y ago
Yep[0], and if you really wanted to, you could use that syntax to express the monadic interface:
putStrLn :: TheWorld -> String -> (TheWorld, ())
main :: TheWorld -> (TheWorld, ())
main world = (part3, ()) where
(part1, _) = putStrLn world "Hello"
(part2, _) = putStrLn part1 ", "
(part3, _) = putStrLn part2 "world!"
It would be a frustrating user experience, but it's a valid and equivalent encoding to Haskell's `IO` type.
[0] I'm ignoring lazy evaluation for now, but `f` could be implemented such that it returns before `g(x)` is evaluated. This is generally not relevant for purely functional code, but it can affect performance and exception-safety.
- afiori 4y agoLazy evaluation is exactly why Haskell has monads and Ocaml does not. the whole point of haskell was to see what happens if try to build a language with the strong requirement of lazy evaluation. If you remove it you also remove any need* for the IO monad * you can obviously use an IO like interface in a non-lazy language, but it is not necessary