Re: [Haskell-cafe] Question on proper use of Data.IORef

2012-06-22 Thread Antoine Latter
On Fri, Jun 22, 2012 at 11:18 AM, Captain Freako wrote: > Okay, I get it now. Thanks to all of you for your quick replies! > > So, here's what I need to do: > > My Haskell code gets called by a higher level C function and asked to > initialize itself. > As part of that initialization, I'm expected

Re: [Haskell-cafe] Question on proper use of Data.IORef

2012-06-22 Thread Captain Freako
Okay, I get it now. Thanks to all of you for your quick replies! So, here's what I need to do: 1. My Haskell code gets called by a higher level C function and asked to initialize itself. 2. As part of that initialization, I'm expected to return a pointer to an instance of a particular

Re: [Haskell-cafe] Question on proper use of Data.IORef

2012-06-22 Thread Max Rabkin
On Fri, Jun 22, 2012 at 5:30 PM, Captain Freako wrote: >  12 main = do >  13 let theValue = 1 >  14 print theValue >  15 theValueRef <- newIORef theValue >  16 bump theValueRef >  17 return theValue theValue is a plain old immutable Haskell variable. "newIORef" creates an IORe

Re: [Haskell-cafe] Question on proper use of Data.IORef

2012-06-22 Thread Adam Smith
theValueRef isn't a pointer to theValue that you can use to somehow change theValue (which is immutable). theValueRef is a reference to a "box" that contains a totally separate, mutable value. When you use newIORef to create theValueRef, it's *copying* theValue into the box. When you mutate theVal

[Haskell-cafe] Question on proper use of Data.IORef

2012-06-22 Thread Captain Freako
Hi experts, I fear I don't understand how to properly use *Data.IORef*. I wrote the following code: 1 -- Testing Data.IORef 2 module Main where 3 4 import Data.IORef 5 6 bump :: IORef Int -> IO() 7 bump theRef = do 8 tmp <- readIORef theRef 9 let tmp2 = tmp + 1 10