DDC/EffectSystem
From HaskellWiki
1 Effect typing vs State monads
Instead of state monads (likeFor example, in Haskell the pure map function has type:
map :: (a -> b) -> [a] -> [b]
mapM :: Monad m => (a -> m b) -> [a] -> m [b]
putStr :: String -> IO ()
In Disciple, this fact is encoded as an effect on the function arrow instead:
putStr :: String -(!e1)> () :- !e1 = !Console
main () = do map putStr ["one", "two", "three"] -- print 'onetwothree' ...
2 Extended type information
But wait, that's evil isn't it?
From the previous example, it might look as though we've lost the information thatmap :: forall a b %r0 %r1 !e0 $c0 . (a -(!e0 $c0)> b) -> List %r0 a -(!e1 $c1)> List %r1 b :- !e1 = !{ !Read %r0; !e0 } , $c1 = f : $c0
Which is a lot more information!
Ignoring the closure information (starting withmap :: forall a b %r0 %r1 !e0 . (a -(!e0)> b) -> List %r0 a -(!e1)> List %r1 b :- !e1 = !{ !Read %r0; !e0 }
The Disciplined Disciple Compiler (DDC) uses this effect discipline to track which parts of the program cause computational effects and which are pure. This allows it to check the type safety of programs that use these effects, and to perform the same sort of code transformation style optimizations as done by other Haskell compilers such as GHC.
3 Behind the scenes
None of this would be useful if you actually had to write these extended types in regular programs. It's a good thing then that, for the most part, you can ignore the extended region, effect and closure information when writing code.
The definition ofmap :: (a -> b) -> [a] -> [b] map f [] = [] map f (x : xs) = f x : map f xs
Because all the extra information is orthogonal to the main shape of the type, ie its argument and return data types, the compiler can fill this in for you behind the scenes. We call this type elaboration. The extra information is present in the interface files and core language, but you'll only have to worry about it if you import foreign functions from C land or start to mix laziness with destructive update in the same program.
