[Haskell-cafe] What are side effects in Haskell?

Hans van Thiel hthiel.char at zonnet.nl
Sun Dec 28 11:44:30 EST 2008


On Sat, 2008-12-27 at 11:54 -0600, Jake McArthur wrote:
> Hans van Thiel wrote:
> > However, some functions in Haskell may have side effects, like printing
> > something on the screen, updating a database, or producing a random
> > number. These functions are called 'actions' in Haskell.
> 
> Not really true (disregarding things like unsafePerformIO). I haven't 
> been following this thread, so I don't know if anybody else has 
> suggested this, but perhaps it would be helpful to distinguish between 
> evaluating expressions and performing actions.
> 
> Evaluation is simply graph reduction, which is Haskell's only method of 
> computation. There are no side-effects when you evaluate an expression 
> (again, disregarding unsafePerformIO and company), even if that 
> expression evaluates to an IO action.
> 
> To perform an action is to cause the side-effect which that action 
> represents. *You* never perform an action in Haskell. The runtime does. 
> All you do is say how to evaluate those actions.
> 
> Essentially, what the IO monad does is give you a DSL for constructing 
> (by evaluation) effectful, imperative programs at runtime. The runtime 
> will cause your program to evaluate the next action, then perform it, 
> then cause your program to evaluate the next action, then perform it,
> and so on. At no point is the purity of your program broken by this.
> 
[snip]

I'm starting to understand it now...thanks again to everybody for all
the helpful replies!

Best regards,

Hans van Thiel




More information about the Haskell-Cafe mailing list