[Haskell-cafe] Why not assign a type to unsafePerformIO?
Justin Bailey
jgbailey at gmail.com
Wed Oct 3 17:47:00 EDT 2007
One of the "holes" in real-world Haskell is you never know if a
library/function is calling unsafePerformIO and you have to trust the
library author. I recognize the necessity of the function, but should it
announce itself? unsafePerformIO has this type:
unsafePerformIO :: IO a -> a
Would there be any value to making it have a type that can be stripped off,
like some other monads? For example, providing a "runUnsafe" or similar:
data UnsafePerformIO a = Unsafe a
runUnsafe :: UnsafePerformIO a -> a
runUnsafe (Unsafe o) = o
and changing unsafePerformIO to have the type:
unsafePerformIO :: IO a -> UnsafePerformIO a
It seems it would be valuable to have functions announce when they use
unsafePerformIO, but additionally allow it to be stripped off. So the
classic
launchMissiles :: a -- Uses unsafePerfomIO!
Would become
launchMissiles :: UnsafePerformIO a
Which could be stripped off it you wanted:
evilDictatator :: a
evilDictator = runUnsafe $ launchMissiles
But doesn't have to be:
incompetentDictator :: a
incompetentDictator = launchMissiles -- Doesn't type check!
I doubt this is original - does it buy anything?
Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071003/fffda784/attachment-0001.htm
More information about the Haskell-Cafe
mailing list