The following is purely personal understanding, if wrong, welcome to spray me out.

1. What is an algebra?

If you recall advanced elementary school math, it would look like this:

2x + 3y + 4z
Copy the code

We could call this algebra getNum.

2. Become a function

function x() {}
function y() {}
function z() {}

function getNum() {
    let a = 2 * x()
    let b = 3 * y()
    let c = 4 * z()
    return a + b + c
}
Copy the code

The x, y and Z functions in the above code are the three variables in the “algebraic” getNum.

3. What’s the problem?

GetNum depends on x, y, and z functions.

Sort by function: what to do -> getNum(), how to do -> x() y() z().

The “what” is coupled with the “how”.

4. How to decouple?

function getNum() {
    let a = 2 * perform `x`
    let b = 3 * perform `y`
    let c = 4 * perform `z`
    return a + b + c
}
Copy the code

Okay, let’s define the “what” to keep the main flow flowing. I don’t give a shit how.

As for “how to”, you can write it anywhere, like in another file:

try {
  getNum();
} handle (effect) {
  if (effect === 'x') {
    // ...
  } else if (effect === 'y') {
    // ...
  } else if (effect === 'z') {
      // ...}}Copy the code

WARNING: This is pseudocode. Currently, js does not implement this syntax.

5. What are algebraic effects?

Effects, “Effects,” are the brothers X, y, and z, and these three functions work, and they’re called “Effects.”

Algebraic, mind you, is an adjective.

What are algebraic effects?

The effect is inserted into the function as a variable in an algebraic expression.

So “code effect” is a dirty translation. The full term should be “effect like variable in algebra”.

This is my understanding, over 😇.


And if you think what I’m saying is crazy,

Take a look at this: Overreacted. IO /algebraic…

Throw in Chinese version: zhuanlan.zhihu.com/p/76158581