|
| 1 | +# purescript-io |
| 2 | + |
| 3 | +An IO monad for PureScript. |
| 4 | + |
| 5 | +Don't ask. Don't tell. Joyfully use in secrecy. |
| 6 | + |
| 7 | +# Introduction |
| 8 | + |
| 9 | +PureScript's effect system is based on row types, and has no semantic or |
| 10 | +algebraic basis. Often, the effect labels have poorly-defined meanings, and |
| 11 | +different libraries use completely different labels to represent the same or |
| 12 | +overlapping effects. |
| 13 | + |
| 14 | +While the effect system is undoubtedly useful, there are cases where it's more |
| 15 | +of a hindrance — where it doesn't make reasoning about code easier, but instead, |
| 16 | +merely adds a ton of boilerplate and semantically meaningless labels get |
| 17 | +threaded through endless stacks of functions. |
| 18 | + |
| 19 | +In those cases, `IO` is here to the rescue! |
| 20 | + |
| 21 | +`IO a` represents a computation that may be synchronous or asynchronous, and |
| 22 | +which will either yield a value of type `a`, run forever, or halt with a |
| 23 | +catchable exception. |
| 24 | + |
| 25 | +Under the covers, `IO` is based on `Aff`, and there is no wrapper so there is |
| 26 | +no runtime overhead or performance penalty for `IO`. |
| 27 | + |
| 28 | +# Usage |
| 29 | + |
| 30 | +`IO` only has one function, which should only be used in your `main`: |
| 31 | + |
| 32 | +```haskell |
| 33 | +runIO :: forall a. IO a -> AffIO a |
| 34 | +``` |
| 35 | + |
| 36 | +This converts an `IO` into an `Aff`, which you can then "convert" into a |
| 37 | +runnable `Eff` using `launchAff` or `runAff`. |
| 38 | + |
| 39 | +The effect row is closed, which is intentionally because `INFINITY` represents |
| 40 | +all possible effects. This will help ensure you only call `runIO` at the top |
| 41 | +level of your program. |
| 42 | + |
| 43 | +Besides this, `IO` has almost all the same instances as `Aff`, and may be used |
| 44 | +in the same way. In addition, a new `MonadIO` class has been introduced which |
| 45 | +allows you to lift `IO` computations into other monads that are as powerful. |
| 46 | + |
| 47 | +Happy nuke launching! |
0 commit comments