Hello, I am interested in using global variables (in GHC). I need a variable to store list of Integers to store temporary results. I have been reading the module MVar, but I wonder if there is an alternative way of doing it. I have already implemented my function using an auxiliar argument where I put my lists of Integers. Will the use of a global variable improve my function? Thanks in advance, J. Ignacio
JIGG> alternative way of doing it. I have already implemented my function JIGG> using an auxiliar argument where I put my lists of Integers. Will JIGG> the use of a global variable improve my function? There is no such thing as mutable variable (as in imperative languages) in Haskell (and my guess is that you are looking exactly for that type), so I guess that for now you must bear with aux. parameter. Use of state monad will help to improve the look of your function, but learning curve for monads could be steep. -- Dmitry Astapov //ADEpt E-mail: adept@umc.com.ua GPG KeyID/fprint: F5D7639D/CA36 E6C4 815D 434D 0498 2B08 7867 4860 F5D7 639D
Hello, I am interested in using global variables (in GHC). I need a variable to store list of Integers to store temporary results. I have been reading the module MVar, but I wonder if there is an alternative way of doing it. I have already implemented my function using an auxiliar argument where I put my lists of Integers. Will the use of a global variable improve my function?
There's many ways to achieve the same goals as C programmers achieve using mutable (global) variables including using laziness, use of "accumulator" arguments, and, supported by most compilers but not standard Haskell, mutable variables. (Unlearning imperative programming habits is one of the big challenges in learning Haskell.) Since there are so many ways to avoid mutable variables and (many less) circumstances where mutable variables are the best solution, it's hard to give useful advice without more information about the problem. -- Alastair Reid reid@cs.utah.edu http://www.cs.utah.edu/~reid/
participants (3)
-
Alastair David Reid -
Dmitry Astapov -
Juan Ignacio García García