[Haskell-cafe] why cannot i get the value of a IORef variable ?

Kyle Murphy orclev at gmail.com
Thu Oct 22 01:19:22 EDT 2009


I assume you're trying this at the GHCi prompt, which is where you're
problem is coming from, specifically on the first line.
When you do:
> let aaa = unsafePerformIO $ newIORef []
GHCi takes a wild stab at the type of [] and comes up with the type [()], so
now you have a IORef [()] type, which is why when you try
to store [1,2,3] in the IORef you get back [(),(),()]. Try this instead and
it should work:
> let aaa = unsafePerformIO $ newIORef ([] :: [Int])

-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.


On Thu, Oct 22, 2009 at 01:02, zaxis <z_axis at 163.com> wrote:

>
> > let aaa = unsafePerformIO  $ newIORef []
> > writeIORef aaa [1,2,3]
> > readIORef aaa
> [(),(),()]
>
> sincerely!
> --
> View this message in context:
> http://www.nabble.com/why-cannot-i-get-the-value-of-a-IORef-variable---tp26004111p26004111.html
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091022/03c82082/attachment.html


More information about the Haskell-Cafe mailing list