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: 2004-12-13 (10:06)
From: Michael Walter <>
Subject: Re: [Caml-list] environment idiom
On Mon, 13 Dec 2004 18:21:17 +0900 (JST), Jacques Garrigue
> You make me curious. > By the way, if you want an example of non referentially code,
> this looks easy:
>    do
>      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
> 0.
Ah no, the key point is that this is not a function but a computation.
In order to be not referentially transparent, you would have to run
it. But you cannot do that -- the key point about the IO monad is that
you can just compose computations involving I/O, but the only time
those computations are actually executed is when "main" is invoked by
the runtime.

> 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?
No, besides referential transparency having a definite technical
meaning, you can clearly see what you are getting by simply looking at
the type (IO Int).