- Define the algebra: what we want to be able to do, but not how we will do it.
- Use the algebra to construct a program.
- Create an interpreter of the algebra.
- Run the program using the interpreter.
Define the algebra:
import cats._| #include <cmath> | |
| #include <cstdio> | |
| #include <vector> | |
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| int main() { | |
| /* Enter your code here. Read input from STDIN. Print output to STDOUT */ |
Define the algebra:
import cats._| # Algebras: Free vs. Tagless Encoding | |
| ## The General Pattern | |
| 1. Define the algebra: _what_ we want to be able to do, but not _how_ we will do it. | |
| 2. Use the algebra to construct a program. | |
| 3. Create an interpreter of the algebra. | |
| 4. Run the program using the interpreter. | |
| ## Tagless encoding | |
| Define the algebra: | |
| ```scala | |
| import cats._ |