What is the relationship between the Purescript types Eff
and Aff
? Is it possible to convert between them?
I'm just starting out with Purescript coming from Haskell, and it seems like both types roughly serve the role that IO
has in Haskell. Is that fair to say?
Eff
is a synchronous effect monad. It is used to sequence effectful foreign JavaScript code - things like random number generation, reading and writing mutable values, writing to the console and throwing and catching exceptions.
Aff
is an asynchronous effect monad. It can handle and sequence effectful asynchronous code, like AJAX requests, timeouts, and network and file IO. It can also perform synchronous effects by using liftEff
. And it also provides a nice mechanism for handling errors.
It is possible to convert from Eff
to Aff
using liftEff
(everything which doesn't pause is an instance of something which is allowed to pause), but the other direction is not possible in general. Aff
actions can be run in an Eff
context by providing a callback.
Haskell's IO
is similar to both, but closer to Aff
than Eff
in that IO
actions can represent asynchronous things (see threadDelay
for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With