2
2
3
3
[ ![ Latest release] ( http://img.shields.io/github/release/purescript/purescript-effect.svg )] ( https://github.com/purescript/purescript-effect/releases )
4
4
[ ![ Build status] ( https://github.com/purescript/purescript-effect/workflows/CI/badge.svg?branch=master )] ( https://github.com/purescript/purescript-effect/actions?query=workflow%3ACI+branch%3Amaster )
5
+ [ ![ Pursuit] ( https://pursuit.purescript.org/packages/purescript-effect/badge )] ( https://pursuit.purescript.org/packages/purescript-effect )
5
6
6
7
The ` Effect ` monad, for handling native side effects.
7
8
@@ -18,17 +19,17 @@ the standard type PureScript uses to handle "native" effects, i.e. effects
18
19
which are provided by the runtime system, and which cannot be emulated by pure
19
20
functions. Some examples of native effects are:
20
21
21
- * Console IO
22
- * Random number generation
23
- * Exceptions
24
- * Reading/writing mutable state
22
+ - Console IO
23
+ - Random number generation
24
+ - Exceptions
25
+ - Reading/writing mutable state
25
26
26
27
And in the browser:
27
28
28
- * DOM manipulation
29
- * XMLHttpRequest / AJAX calls
30
- * Interacting with a websocket
31
- * Writing/reading to/from local storage
29
+ - DOM manipulation
30
+ - XMLHttpRequest / AJAX calls
31
+ - Interacting with a websocket
32
+ - Writing/reading to/from local storage
32
33
33
34
All of these things may be represented in PureScript by the ` Effect ` type.
34
35
A value of the type ` Effect a ` represents a computation which may perform
@@ -122,12 +123,12 @@ and in the corresponding JavaScript module:
122
123
123
124
``` javascript
124
125
// Counter.js
125
- exports .incrCounter = function () {
126
+ exports .incrCounter = function () {
126
127
if (! window .globalCounter ) {
127
128
window .globalCounter = 0 ;
128
129
}
129
130
return ++ window .globalCounter ;
130
- }
131
+ };
131
132
```
132
133
133
134
For more information about the FFI (Foreign Function Interface), see
@@ -149,16 +150,19 @@ compiler produces the following JavaScript:
149
150
150
151
``` javascript
151
152
var printRandom = function __do () {
152
- var $0 = Effect_Random .random ();
153
- return Effect_Console .log (Data_Show .show (Data_Show .showNumber )($0))();
153
+ var $0 = Effect_Random .random ();
154
+ return Effect_Console .log (Data_Show .show (Data_Show .showNumber )($0))();
154
155
};
155
156
```
156
157
157
158
whereas a more naive compiler might, for instance, produce:
159
+
158
160
``` javascript
159
- var printRandom = Control_Bind .bind (Effect .bindEffect )(Effect_Random .random )(function ($0 ) {
161
+ var printRandom = Control_Bind .bind (Effect .bindEffect )(Effect_Random .random )(
162
+ function ($0 ) {
160
163
return Effect_Console .log (Data_Show .show (Data_Show .showNumber )($0));
161
- });
164
+ }
165
+ );
162
166
```
163
167
164
168
While this is a small improvement, the benefit is greater when using
0 commit comments