[Haskell-cafe] unsafePerformIO: are we safe?

Lennart Augustsson lennart at augustsson.net
Wed Sep 26 17:46:17 EDT 2007


You could do this:

r :: IORef [a]
r = unsafePerformIO $ newIORef []

cast :: a -> b
cast a = unsafePerformIO $ do
    writeIORef r [a]
    x <- readIORef r
    return $ head x


On 9/26/07, Dan Piponi <dpiponi at gmail.com> wrote:
>
> On 9/26/07, Lennart Augustsson <lennart at augustsson.net> wrote:
> > Things can go arbitrarily wrong if you misuse unsafePerformIO, you can
> even
> > subvert the type system.
>
> So...if I was in a subversive kind of mood (speaking hypothetically),
> what would I have to do?
> --
> Dan
>
> >
> >
> > On 9/26/07, Jorge Marques Pelizzoni < jpeliz at icmc.usp.br> wrote:
> > >
> > > Hi, all!
> > >
> > > This is a newbie question: I sort of understand what unsafePerformIO
> does
> > > but I don't quite get its consequences. In short: how safe can one be
> in
> > > face of it? I mean, conceptually, it allows any Haskell function to
> have
> > > side effects just as in any imperative language, doesn't it? Doesn't
> it
> > > blow up referential transparency for good? Is there anything intrinsic
> to
> > > it that still keeps Haskell "sound" no matter what unsafePerformIO
> users
> > > do (unlikely) or else what are the guidelines we should follow when
> using
> > > it?
> > >
> > > Thanks in advance. Cheers,
> > >
> > > Jorge.
> > >
> > > _______________________________________________
> > > Haskell-Cafe mailing list
> > > Haskell-Cafe at haskell.org
> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > >
> >
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> >
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070926/20d2c72e/attachment-0001.htm


More information about the Haskell-Cafe mailing list