[Haskell-cafe] global variables

Dougal Stanton ithika at gmail.com
Thu May 17 09:46:56 EDT 2007


On 17/05/07, Eric <eeoam at ukfsn.org> wrote:
> H|i,
>
> Does anyone know of a simple and straightforward way to use global
> variables in Haskell?
>

You can pass around an environment with the State or Reader monads
(read/write and read-only respectively). If you want to do IO with the
data you'll probably need the transformer equivalents: StateT or
ReaderT.

I think there are some hackish ways of making IO variables but I don't
know how that's done. I'd imagine it's frowned on from a stylistic
point of view, too...

D.


More information about the Haskell-Cafe mailing list