External Publication
Visit Post

GHC Proposal: Top-level IO initialized bindings

Haskell Community [Unofficial] July 1, 2026
Source

prophet:

blah_impl :: Blurg
blah_impl = unsafePerformIO someEffectfulFunction
{-# OPAQUE blah_impl #-}

blah :: IO Blurg
blah =  pure blah_impl

I like that, but I would instead suggest:

data Box a = Box a

blah_impl :: Box Blurg
blah_impl = unsafePerformIO (Box <$> someEffectFulFunction)
{-# OPAQUE blah_impl #-}

blah :: IO Blurg
blah = let !(Box x) = blah_impl in pure x

That way the IO action will run whenever blah runs for the first time, not only later when the result of blah is forced. And this doesn’t force the Blurg itself.

Discussion in the ATmosphere

Loading comments...