[Haskell-cafe] global variables

Tom Harper rtharper at aftereternity.co.uk
Thu May 17 09:52:30 EDT 2007


You can also use mutable variables (MVars) found in Control.Concurrent.MVar

http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html

They might work depending on your implementation.  The reading and
writing of MVars returns IO actions.

On 5/17/07, Dougal Stanton <ithika at gmail.com> wrote:
> 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.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


-- 
Tom Harper
Computer Science Major '07
Syracuse University
+1 949 235 0185
Public Key: http://aftereternity.co.uk/rth.asc


More information about the Haskell-Cafe mailing list