[Haskell-cafe] Re: Order of Evaluation
miguelimo38 at yandex.ru
Fri May 9 17:42:30 EDT 2008
Oh, you sure?
It is less well known that unsafePerformIO is not type safe. For
test :: IORef [a]
test = unsafePerformIO $ newIORef 
main = do
writeIORef test 
bang <- readIORef test
print (bang :: [Char])
This program will core dump. This problem with polymorphic references
is well known in the ML community, and does not arise with normal
monadic use of references. There is no easy way to make it impossible
once you use unsafePerformIO. Indeed, it is possible to write
coerce :: a -> b with the help of unsafePerformIO. So be careful!
That's the reason why "f" has sometimes LESS general type than "\x ->
f x" in OCaml.
On 10 May 2008, at 01:34, Achim Schneider wrote:
> Miguel Mitrofanov <miguelimo38 at yandex.ru> wrote:
>>> As I understand it Haskell does not specify an order of evaluation
>>> and it would therefore be a mistake to write a program which relies
>>> on a particular evaluation order. This is the 'unsafe' aspect of
>> Hmm... IMHO unsafePerformIO is 'unsafe' because it can lead to type
>> errors in runtime. At least, that seems to be much more dangerous.
> Nope. That'd be unsafeCoerce#, which you never heard of, and I did not
> mention it in this post. Go away. This is not the function you are
> looking for.
> (c) this sig last receiving data processing entity. Inspect headers
> past copyright information. All rights reserved. Unauthorised copying,
> hiring, renting, public performance and/or broadcasting of this
> signature prohibited.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe