If you're writing an application (as opposed to a library), you should almost always use
Aff to run your native side-effectful computations rather than
Effect. Here are some of its advantages:
- prevents "callback hell" for which Node.js is well-known.
- is a stack-safe monad (
Effectis not currently stack-safe).
Before continuing one with this folder's contents, watch Async Programming in PureScript to learn what problem
Aff solves and a tour of its API for how to use it (actual video on YouTube is titled: "LA PureScript Meetup 12/05/17").
If, after watching the above video, you are tempted to figure out how
Aff is difficult to understand. Your time would be better invested elsewhere. Rather, I'd recommend looking at it when you have a better grasp of FP concepts.
First, we'll overview some of
Affs API via some working examples that one can play with. Since all programs must be run in
Effect, this will show the simplest way to start running computations in the
Second, we'll show one way for making it possible to run an
Effect-based computations in an
Aff monadic context. (Note: this solution won't work for the
ST monadic context in the
Local-State.purs example.) Then, we'll show how to fix the issue we experienced in our the
Third, we'll use the
Node.ReadLine library to show how to convert
Effect-based computations that require callbacks into
Aff-based computations via
makeAff. We'll also show the more complicated way to run a computation in the
Aff monad, but which exposes all of
Finally, we'll link to other
Aff-based libraries that one will likely find helpful.