ioref Questions
1
Solved
I was wondering if there was a legitimate usage for IORef in Haskell? More specifically I would be thankful if someone could address the following or point to an appropriate place to know more abou...
4
Solved
The signature of modifyIORef is straightforward enough:
modifyIORef :: IORef a -> (a -> a) -> IO ()
Unfortunately, this is not thread safe. There is an alternative that adresses this is...
Buie asked 22/9, 2016 at 13:25
1
Solved
Background
I am a Schemer starting to learn Haskell. I am trying to implement a Scheme interpreter in C, following chapter 4 of SICP. It turns out programming directly in C is too hard. So I decid...
1
Solved
To measure the performance of those Refs, I dumped the assembly produced by GHC on the following code :
import Data.IORef
main = do
r <- newIORef 18
v <- readIORef r
print v
I expected...
Lunar asked 29/8, 2016 at 9:25
2
Solved
I was doing some experiments with concurrency and memory visibility and ran into this strange behavior (see comments inline):
module Main
where
import Data.IORef
import Control.Concurrent
import...
Cumae asked 31/8, 2014 at 23:16
2
Solved
Wondering how best to combine the Control.Lens package with IORefs. Specifically I'd like to be able to use atomicModifyIORef with lenses so that i can supply a function of type a -> (a, b) and ...
Tableware asked 21/8, 2014 at 10:18
3
Solved
I have been trying to encode an algorithm in Haskell that requires using lots of mutable references, but it is (perhaps not surprisingly) very slow in comparison to purely lazy code.
Consider a ver...
Ramage asked 5/6, 2014 at 19:13
3
Solved
The docs say:
In a concurrent program, IORef operations may appear out-of-order to
another thread, depending on the memory model of the underlying
processor architecture...The implementation i...
Terribly asked 2/2, 2014 at 3:40
1
Solved
I am working on an program that uses a large list of IORef's to a data type. Which is the more memory/processor-efficient way to do this:
[IORef Foo]
or
IORef [Foo]
Ignore the fact that I a...
Custommade asked 15/1, 2014 at 5:40
2
Solved
What exactly is the difference between STRef and IORef and when do I use each of them? As far as I can tell they both are for mutable state so whats the point of both of them existing?
1
Solved
I noticed that Data.UnionFind uses the IO monad to provide pointers via IORefs. I imagine everyone happily calls unsafePerformIO when using it locally in pure code, since the data structure is so w...
Readjust asked 24/4, 2012 at 13:18
2
Solved
I've been trying to get a understanding of concurrency, and I've been trying to work out what's better, one big IORef lock or many TVars. I've came to the following guidelines, comments will be app...
Essayistic asked 19/4, 2012 at 1:56
3
Solved
If I share an IORef among multiple threads, and use atomicModifyIORef to write to it:
atomicModifyIORef ref (\_ -> (new, ()))
Is it safe to read the value with plain old readIORef? Or is ther...
Denotation asked 17/2, 2012 at 12:14
2
Solved
I have a data type which contains an IORef as an important element. This means there is not a clean way to make it a member of the show type class. This is not too bad as I have a print function in...
Cleanshaven asked 30/11, 2011 at 20:10
4
Solved
One thing that has always confused me is whether or not it's an okay time to use an IORef. Are there any guidelines that should be followed when deciding whether or not to use an IORef for a task? ...
3
Solved
I am working through Write Yourself a Scheme in 48 Hours (I'm up to about 85hrs) and I've gotten to the part about Adding Variables and Assignments. There is a big conceptual jump in this chapter, ...
Dori asked 4/4, 2011 at 23:33
1
Solved
I'm having a little trouble understanding the basic difference between the IORef type and the MVar type in Haskell. Can someone help me out with this? They appear to solve the same problem. MVar se...
Turnbow asked 7/3, 2011 at 6:49
3
Solved
I found some sample code, and changed it a little
counter = unsafePerform $ newIORef 0
newNode _ = unsafePerformIO $
do
i <- readIORef counter
writeIORef counter (i+1)
return i
Which ret...
Leo asked 16/12, 2010 at 14:19
1
Solved
I made the following function which is specific for the IO monad:
memoIO :: MonadIO m => m a -> IO (m a)
memoIO action = do
ref <- newMVar Nothing
return $ do
x <- maybe action retu...
1
© 2022 - 2024 — McMap. All rights reserved.