-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
README Effect and Aff #211
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,20 @@ main = launchAff_ do | |
log response.body | ||
``` | ||
|
||
## Effect and Aff | ||
|
||
`Effect` 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.[<sup>1</sup>](https://stackoverflow.com/questions/37661391/what-are-eff-and-aff) | ||
|
||
`Aff` is an asynchronous effect monad. It can handle and sequence effectful asynchronous code, like AJAX requests, timeouts, and network and file IO. | ||
It also provides a nice mechanism for handling errors. | ||
|
||
Furthermore, `Aff` can perform synchronous effects by using `liftEffect`. In other words, `Effect` is a special case of `Aff`, for the special case that we expect the effect to complete immediately. `Effect` is in the core libraries instead of `Aff` for two reasons. | ||
|
||
1. The implementation of `Effect` is much simpler than `Aff`, which makes a big difference for non-JavaScript backends. | ||
2. `Effect` is much faster than `Aff`, and we expect most effects to complete synchronously, so usually `Effect` will suffice. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this reasoning is totally correct, though it may be partially true. It's certainly not nuanced enough, and I'd argue that it is not necessary to document this in the preamble to the README. Aff isn't designed to be portable (or at least isn't designed well for that purpose). The API is specifically around mapping JS style evented callbacks to a direct style. For many runtimes this is just isn't necessary, because their runtimes already provide it as part of normal Aff also isn't necessarily slower than Effect. In alternative runtimes, this is likely the case, yes, if they implemented bindings to Aff. In JS, Aff can beat Effect in some cases depending on how the Effect is constructed and what optimizations the compiler was able to apply. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Right, this section has no nuance at all; the intended audience here is people who are just starting out in PureScript and have never encountered an effect monad before in their life. I want beginners to be able to read this in less than a minute and then come away with first-approximation answers to the questions:
Then they can decide if they want to read about the nuance in the Documentation section which follows. How do you think we should explain why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn’t clear to me that we need to explain that at all here. What does that have to do with when to use Effect or Aff? Do we provide that reason in any other contrib library? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a better way to go around it is answering the question "Why isn't Aff the default effect type?", or "Why isn't Aff the effect type I usually encounter?" I feel like "Why isn't it in core?" is trying to stand-in for that, but I don't think that a complete beginner has any internalized distinction about what core vs contrib even means. If they do, it may not even be accurate since there is no defined policy other than who maintains it (compiler team vs community team). To me, "Why isn't it in core?" is just trivia (and the answer should be nuanced). It's only a question one might ask if you note "Effect is in core. Aff is not." as an important distinction for a beginner, which I don't think is the case. For example, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I deleted the reasons why Effect is in core instead of Aff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ( purerl is an example of a PureScript backend for which |
||
|
||
Many I/O-related packages in the PureScript ecosystem provide both an asynchronous callback-based `Effect` API and an `Aff` API for the same feature. When you encounter this, you should almost always prefer the `Aff` API. You will find the `Aff` API is much simpler to use correctly. | ||
|
||
## Documentation | ||
|
||
`aff` documentation is stored in a few places: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we have Affjax, but AJAX is just not a term that is used anymore. I think we should keep it in the early 2000s 😄.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.