Skip to content

Instantly share code, notes, and snippets.

@oumsofiane1
oumsofiane1 / exercice1.cpp
Created November 4, 2018 18:19
Exercice from hackerrank
#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 */

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:

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