Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] environment idiom
From: Thomas Fischbacher <Thomas.Fischbacher@Physik.Uni-Muenchen.DE>
> 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:

You make me curious. Most of the code I've seen using the IO monad (or
the state transformer monad) was just transliterating imperative to
monadic code. Of course using closures, but not that much, and you can
certainly do that in an impure functional language also.

So what is so incredible about the IO monad?

By the way, if you want an example of non referentially code, this
looks easy:

     x <- readInt
     y <- readInt
     return (x-y)

(The syntax and functions may be wrong but you get the idea.)
Of course according to your definition this contains nothing that is
not referentially transparent once you've taken the syntactic sugar.
But looking at the code, it looks like readInt is executed twice
returning different results, i.e. this function does not always return
So I suppose this is just an instance of what you see is _not_ what
you get, but wasn't referencial transparency about avoiding that?

    Jacques Garrigue