Should we have primitive fill-once variables?

Joachim Breitner mail at
Fri Jun 29 15:51:07 UTC 2018


when reading the subject I was expecting something like this:

   -- | Creates an empty IVar
   newIVar :: IO (IVar a)

   -- | pure! but blocks until the IVar is written
   readIVar :: IVar a -> a 

   -- | tries to write to an IVar. 
   -- Succeeds if it is empty (returning True)
   -- Does nothing if it has been written to (returning False)
   writeIVar :: IVar a -> a -> IO Bool 


   -- | all in one
   newIVar :: IO (a, a -> IO Bool)

Essentially a thunk, but with explicit control over filling it.
In fact, people have implemented something like this using C-- hacks

> This would make MonadFix's implementation much nicer, I think :)

This would suffice for MonadFix, right?

Sorry for derailing the thread :-)


Joachim Breitner
  mail at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <>

More information about the ghc-devs mailing list