[Haskell-cafe] Re: Sometimes I wish there was a global variable

Maurí­cio briqueabraque at yahoo.com
Sat Mar 21 21:47:49 EDT 2009


> Notice that rotX, rotY and pos are meant to be used as comunication
> between the keyboardMouse and display functions. They need to be set as
> 0 first, so display won't do anything. Only when they user press a few
> buttons that those values change, so display behaves accordanly.
> 
> In a state-based language I would place display and keyboardMouse in one
> module and let them communcate to each other like they want. In haskell,
> I'm not quite sure how to do it except by that parameter passing style.

In one module, you can write:

----------
giveMeFunctions = do {
     newIORef ...
     newIORef ...
     newIORef ...
     (...)
     let f1 = ...
     let f2 = ...
     return (f1,f2)
----------

and in the main:

(keyboardMouse,display) <- giveMeFunctions

Best,
Maurício



More information about the Haskell-Cafe mailing list