[Haskell-cafe] Re: [Haskell] IVars

Benja Fallenstein benja.fallenstein at gmail.com
Sun Dec 9 17:08:18 EST 2007

Hi Conal,

On Dec 9, 2007 6:09 PM, Conal Elliott <conal at conal.net> wrote:
> > readIVar' :: IVar a -> a
> > readIVar' = unsafePerformIO . readIVar
> > so, we do not need readIVar'. it could be a nice addition to the
> libraries, maybe as "unsafeReadIVar" or "unsafeReadMVar".
> The same argument applies any to pure function, doesn't it?  For instance, a
> non-IO version of succ is unnecessary.  My question is why make readIVar a
> blocking IO action rather than a blocking pure value, considering that it
> always returns the same value?

>From the rest of Marc's post, I understood the point to be that
readIVar lets you do something that readIVar' does not let you do:
block until the IVar is written, then continue *without* first
evaluating the thunk in the IVar to WHNF. I haven't used IVars myself,
so this isn't informed by hands-on experience, but it does sound
sensible to me that "block until the IVar has been written" and
"evaluate the thunk to WHNF" should be separable.

All the best,
- Benja

More information about the Haskell-Cafe mailing list