# Using unsafePerformIO safely?

**URL:** <https://discourse.haskell.org/t/using-unsafeperformio-safely/4146>\
**Category:** Uncategorized\
**Created:** [February 28, 2022, 2:41pm UTC](https://discourse.haskell.org/t/using-unsafeperformio-safely/4146 "2022-02-28T14:41:23Z")\
**Posts on this page:** 1\
**Showing post:** 69

<div class="post-metadata">

**Author:** ![nomeata](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/nomeata/32/1188_2.png) [@nomeata](https://discourse.haskell.org/u/nomeata)\
**Post date:** [August 25, 2022, 2:18pm UTC](https://discourse.haskell.org/t/using-unsafeperformio-safely/4146/69 "2022-08-25T14:18:36Z")

</div>

The question “when do we know that `unsafePerformIO` is safe” can be specialized to “why do we believe that `runST` is safe?” (which is one possible use of `unsafePerformIO`).

I [asked that before](https://stackoverflow.com/questions/43575670/is-there-a-proof-that-runst-is-indeed-pure), and shortly after an answer was given by [Amin Timany et al in their POPL 2018 paper “A Logical Relation for Monadic Encapsulation of State”](http://iris-project.org/pdfs/2018-popl-runST-final.pdf).

So that establishes _one_ possible way of answering that question. I am not sure how easy it is to extend to other uses of `unsafePerformIO` (e.g. the [tricks I am playing here](http://discourse.haskell.org/t/solving-cyclic-boolean-implications-with-pure-code-and-laziness/4951)), or to safety in the presence of concurrency.

---

_[View the full topic](https://discourse.haskell.org/t/using-unsafeperformio-safely/4146)._
