5 ms·
> In Haskell, when I read an API, I know no effects lurk behind the pure type signatures. I wonder how often unsafePerformIO : IO 'a -> 'a is employed
by enum 15y ago
> In Haskell, when I read an API, I know no effects lurk behind the pure type signatures.
I wonder how often unsafePerformIO : IO 'a -> 'a is employed
- baguasquirrel 15y agounsafePerformIO is not nearly as useful for introducing effects as one might think it would be. Because Haskell is lazy, any effects you might want would have to be grounded in the toplevel IO monad anyway. To answer you directly, I've read code in various Haskell packages, everything from mime to snap, and AFAICT, it is typically used when you need to call a C library. Suppose you need to use OpenSSL's digest algorithms, for example. Because we technically don't know whether or not that library will have effects, we have to use unsafePerformIO.
- eru 15y agoActually you can interpret unsafePerformIO as: "Dear compiler, I know you can't prove that it's safe to call this function here in a lazy setting. Please trust me that it is. Sincerely, the programmer."
- dons 15y agoPrecisely. The burden is on the programmer to provide the evidence that the conditions for calling `unsafePerformIO` are satisfied. (That is, that any side effects are hidden). Most languages have `unsafePerformIO` on every single computation :-)
- baguasquirrel 15y agoIt's like there's a spacesuit full of nuclear waste in every single computation!
- dons 15y agoThe horror!!
- nostrademons 15y agohttp://www.google.com/codesearch?q=unsafePerformIO+-file%3Anhc98+-file%3Aghc http://www.google.com/codesearch?q=unsafePerformIO+-file%3An...