[Haskell-beginners] Count how often a menu has been selected

Felipe Lessa felipe.lessa at gmail.com
Sat Jul 25 08:00:22 EDT 2009


On Sat, Jul 25, 2009 at 01:10:02PM +0200, Bernhard Lehnert wrote:
>     let a = 0
>     onActivateLeaf menuAddOne $ do
>         let a = a+1
>         print a

If you want variables in the impure sense, use IORefs.

    import Data.IORef

    ...

    a <- newIORef 0
    onActivateLeaf menuAddOne $ do
        modifyIORef a (+1)
        print a

--
Felipe.


More information about the Beginners mailing list