Search code examples
scalahaskellfunctional-programmingio-monad

What is the IO Haskell Monad equivalent in Scala standard API?


I know there are some almost identical implementations in Scalaz of IO operators like putStrLn :: String -> IO () and getLine :: IO String but I mean about Scala standard API why there aren't such equivalents? I know Scala is not a pure language as Haskell and there is side effect but I consider that this datatype is so descriptive and useful. I don't know if Try, Option or Either would do the job.


Solution

  • Scala has implicit ambient side-effects, just like C♯, Java, C++, Objective-C, Swift, C, Pascal, Basic, Perl, PHP, Python, Ruby, ECMAScript, etc. There is no type for IO.

    There are third-party libraries that provide an IO type, but it doesn't give the same guarantees as Haskell's: Haskell has only a very few escape hatches (unsafePerformIO), in Scala, pretty much everything is an escape hatch.

    However, there are ideas and I believe even research prototypes for effects systems in Scala, and the streamlined, more powerful, and sound type system of Dotty is probably going to be an even better foundation for that.