In Haskell, we have the IO
monad to deal with side-effects, although, it is not able to expressively track side-effects, you don't really know what type of side effect is really happening:
main :: IO ()
In PureScript, we have the Eff
monad, where you are able to know what type of side-effects happen according to the type signature:
main :: forall e. Eff (fs :: FS, trace :: Trace, process :: Process | e) Unit
Here it is clearly that the main
function has use of the filesystem, of tracing messages to the console and is able to handle the current process, where we have a specific module Control.Monad.Eff
for dealing with side effects, and submodules such as Control.Monad.Eff.Random
and Control.Monad.Eff.Console
.
Taking by example the following:
module RandomExample where
import Prelude
import Control.Monad.Eff
import Control.Monad.Eff.Random (random)
import Control.Monad.Eff.Console (print)
printRandom :: forall e. Eff (console :: CONSOLE, random :: RANDOM | e) Unit
printRandom = do
n <- random
print n
This is so much more specific than using just "Hey, here happens a side-effect, that's it, no more that you need to know!". I've being looking through the web and I didn't see a monad complete enough to track side-effects.
Is there a specific monad in Haskell, like Eff
, for tracking side effects?
Thanks in advance.
IO
has effects, not side-effects. A side-effect would be something evil like a computation pretending to be pure, but doing IO viaunsafePerformIO
. – Cactus