Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Eff and Aff?

Tags:

purescript

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?

like image 451
Chris Martin Avatar asked Jun 06 '16 15:06

Chris Martin


1 Answers

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).

like image 57
Phil Freeman Avatar answered Sep 21 '22 01:09

Phil Freeman