[Haskell-beginners] Global variables
aditya siram
aditya.siram at gmail.com
Wed Jun 29 17:57:49 CEST 2011
Although it is generally considered an anti-pattern, it is possible to
implement a true mutable, global counter [1] a la
every-other-imperative-language in Haskell.
As some other people have indicated you're better off with the State
monad, but this style comes in handy when you need to translate
imperative code into Haskell without having to do a complete redesign.
-deech
[1] http://stackoverflow.com/questions/6302249/how-to-implement-a-global-counter-using-monad/6349651#6349651
On Wed, Jun 29, 2011 at 10:47 AM, Michael Xavier
<nemesisdesign at gmail.com> wrote:
> I think my head isn't on straight this morning. I think I meant something
> more along the lines of Control.Monad.State
>
> On Wed, Jun 29, 2011 at 8:27 AM, Christopher Done <chrisdone at googlemail.com>
> wrote:
>>
>> On 29 June 2011 17:22, Michael Xavier <nemesisdesign at gmail.com> wrote:
>> > I tend to use Control.Monad.Reader for stateful stuff like this. It is
>> > found
>> > in the mtl package
>> > http://hackage.haskell.org/package/mtl-2.0.1.0
>>
>> How would you use reader for a counter?
>
>
>
> --
> Michael Xavier
> http://www.michaelxavier.net
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
More information about the Beginners
mailing list