Difference between revisions of "DDC/EffectSystem"

From HaskellWiki
< DDC
Jump to navigation Jump to search
Line 4: Line 4:
 
The main benefit of effect typing is that the type of functions that cause effects have the same shape as their 'pure' counterparts, which lets us re-use more code.
 
The main benefit of effect typing is that the type of functions that cause effects have the same shape as their 'pure' counterparts, which lets us re-use more code.
   
for example, in Haskell the 'pure' map function has type:
+
For example, in Haskell the 'pure' map function has type:
 
<haskell>
 
<haskell>
 
map :: (a -> b) -> [a] -> [b]
 
map :: (a -> b) -> [a] -> [b]

Revision as of 00:48, 19 March 2008

Effect typing

Instead of state monads (like IO), Disciple uses default strict evaluation and effect typing to deal with computational effects.

The main benefit of effect typing is that the type of functions that cause effects have the same shape as their 'pure' counterparts, which lets us re-use more code.

For example, in Haskell the 'pure' map function has type:

    map :: (a -> b) -> [a] -> [b]

but if we need to use an effectful function defined in terms of a state monad, we must use the monadic version, mapM instead.

    mapM :: Monad m => (a -> m b) -> [a] -> m [b]