[Haskell-cafe] Why not assign a type to unsafePerformIO?
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
launchMissiles :: a -- Uses unsafePerfomIO!
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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe