Monad to track side effects

At Haskell, we have the IO monad to deal with side effects, although it is not able to express expressive side effects, you really don't know what type of side effect is actually happening:

 main :: IO () 

In PureScript, we have the Eff monad, where you can find out which side effects occur according to a signature like:

 main :: forall e. Eff (fs :: FS, trace :: Trace, process :: Process | e) Unit 

Here it is obvious that the main function uses the file system, monitors messages on the console and can process the current process, where we have a special Control.Monad.Eff module for solving side effects and submodules such as Control.Monad.Eff.Random and Control.Monad.Eff.Console .

Taking the following as an example:

 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 much more specific than using only "Hey, there is a side effect here, which he is, no more than what you need to know!". I am browsing the internet and I have not seen the monad complete enough to track side effects.

Is there a specific monad in Haskell, like Eff , for tracking side effects?

Thanks in advance.

+8
haskell monads
source share
1 answer

There are several libraries that define similar effect systems for Haskell.

I worked with extensible-effects and found it pretty easy to add limited IO , like STDIO , FileIO , effects. The lack of compiler support is a little less nice to use.

If you want to try, you can find inspiration in existing effects for the extensible-effects framework: http://hackage.haskell.org/packages/#cat:Effect

There seems to be a version of extensible-effects that doesn't use Typeable to track effects: http://hackage.haskell.org/package/effin . This should make it nicer to write new effects.

+4
source share

All Articles