[Haskell-cafe] Re: [Haskell] IORef sharing
Bulat Ziganshin
bulat.ziganshin at gmail.com
Mon Oct 27 18:44:45 EDT 2008
Hello Rodney,
Tuesday, October 28, 2008, 1:27:26 AM, you wrote:
> Now I define an IORef and a couple of counters that share
> the IORef,
>> iio :: IO (IORef Int)
>> iio = newIORef 0
>> ic1 = do { io <- iio ; count io 0 }
>> ic2 = do { io <- iio ; count io 0 }
> So apparently my mental picture of an IORef as a pointer
> to a value is wrong. I need a new mental picture. What's
> going on here?
this part is right. but "iio = newIORef 0" doesn't define IORef,
instead it defines *operation* that creates new IORef and returns it
then ic1 and ic2 are *operations* that performs iio, creating new IORef
on each call, and then use this new IORef in further operation
look at http://haskell.org/haskellwiki/IO_inside
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list