Version française
Home     About     Download     Resources     Contact us    
Browse thread
environment idiom
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Thomas Fischbacher <Thomas.Fischbacher@P...>
Subject: Re: [Caml-list] environment idiom

On Sun, 12 Dec 2004, Michael Walter wrote:

> Again I believe we are talking about different kinds of "purity".
> Thomas is obviously right in that the StateTransformer monad (modulo
> unsafe conversions) is pure, you are obviously right in the
> (different) point that _running_ an IO fragment has side effects.

The key issue is: by not doing I/O, but talking about plans how to do I/O, 
you go to a higher level of abstraction that allows you to do magic with 
such plans which you just plainly miss if you only know the imperative 
ways. It's just like everyone knows how to add (i.e. arithmetics), but 
once you learned to talk about properties of addition (i.e. algebra), you 
have a much richer point of view that allows you to do quite miraculous 
things.

Of course, it's possible to just forget about all that and fall back to 
transliterating imperative code to IO monad code, but it is just as well 
possible to find the sum of all the numbers from 1 to 1000 using the 
following piece of Maple code:

> proc sum_n(k)
> local result,i;
> for i from 1 to k do result:=result+i: od: result;
> end;
>
> sum_n(1000);

One surely can do this, and many people work in such a way to solve 
such problems, as they are used to it, but considering the power that 
Maple offers you, this is nothing but gross abuse of the system.

It's just the same with Haskell and the IO monad.


-- 
regards,               tf@cip.physik.uni-muenchen.de              (o_
 Thomas Fischbacher -  http://www.cip.physik.uni-muenchen.de/~tf  //\
(lambda (n) ((lambda (p q r) (p p q r)) (lambda (g x y)           V_/_
(if (= x 0) y (g g (- x 1) (* x y)))) n 1))                  (Debian GNU)