[Haskell-cafe] Top Level <-

Sittampalam, Ganesh ganesh.sittampalam at credit-suisse.com
Tue Sep 2 04:09:10 EDT 2008


John Meacham wrote:
On Fri, Aug 29, 2008 at 04:33:50PM -0700, Dan Weston wrote:

>> C++ faced this very issue by saying that with global data,
>> uniqueness of initialization is guaranteed but order of
>> evaluation is not. Assuming that the global data are 
>> merely thunk wrappers over some common data source, this 
>> means that at minimum, there can be no data dependencies 
>> between plugins where the order of evaluation matters.

> Fortunately, we can do a whole lot better with haskell, the 
> type system guarentees that order of evaluation is irrelevant
> :) no need to specify anything about implementations.

Can't you write two recursive modules with <- that depend on
each other, so that there's no valid initialisation order?

Contrived example follows:

module Module1 where

glob1 :: IORef Int
glob1 <- mod2 >>= newIORef 

mod1 :: IO Int
mod1 = readIORef glob1

module Module2 where

glob2 :: IORef Int
glob2 <- mod1 >>= newIORef 

mod2 :: IO Int
mod2 = readIORef glob2

It might need some strictness annotations to actually cause
non-termination at initialisation rather than just make the results
of mod1 and mod2 be _|_.

I think those initialisers do satisfy ACIO, though I'm not certain -
from the point of view of dataflow, you can certainly remove them
both together if the rest of the code doesn't use mod1 or mod2, and
likewise they commute with any other IO operations. But on the other
hand there's no way to actually put them in an order that doesn't
cause non-termination.

Cheers,

Ganesh


==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================



More information about the Haskell-Cafe mailing list