Since Haskell's data are Immutable,how would you globally store a list that can be modified by any function?Would you muiltithread it and store it in a loop?or write the list to a file? I need to record the amount of buttons the user clicks.
Generally you don't since, as you say, Haskell's data is (mostly) immutable.
If you are going to start with a list and run it through a whole bunch of update functions, you have each function take the list as an argument and return the updated list as a result. Then you have some coordinating function (possibly main
, if this is all your program is doing) that feeds the output of each update to the next updater.
It is possible to use things like the State monad to program with implicit state update, or using STRefs in the ST monad or IORefs in the IO Monad to program with implicit state update that can actually update things in-place. But Haskell programmers would usually prefer not to put a large portion of their programs in such monads to have implicit global access to writeable values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With