This page is meant to contain discussion about global state and "things with identity". It's a companion to Adrian's http://www.haskell.org/hawiki/GlobalMutableState, but that's in the old Wiki, so I thought it better to start a new page.
See also Ian Stark's ACIO message http://www.haskell.org/pipermail/haskell-cafe/2004-November/007664.html.
The kind of applications we have in mind are:
- A source of random numbers, or of unique numbers. This should be on a per-thread basis.
- The value of 'stdin' or 'stdout'. We don't want to mutate this, but we might want to set the value for sub-computations, including any spawned threads.
A straw man
Here's a straw-man proposal.
- New top-level declaration to allocate a new key
key rng :: Key StdGen
- You can read and write global state and local state:
readLS, readGS :: Key a -> IO a writeLS, writeGS :: Key a -> a -> IO a
- Keys have equality but not ordering. We probably want to provide efficient finite maps on keys.
- When you forkIO a thread,