Skip to content

Instantly share code, notes, and snippets.

@cqfd
Created July 28, 2018 03:06
Show Gist options
  • Save cqfd/859680dbfab56d12f485fe692ae8e7b1 to your computer and use it in GitHub Desktop.
Save cqfd/859680dbfab56d12f485fe692ae8e7b1 to your computer and use it in GitHub Desktop.
C++ experiments
template <typename T>
struct LinkedList {
T head;
LinkedList *tail;
};
template<typename Monoid>
typename Monoid::T fold(LinkedList<typename Monoid::T> *l) {
typename Monoid::T acc = Monoid::mempty();
while (l) {
acc = Monoid::mappend(acc, l->head);
l = l->tail;
}
return acc;
};
struct IntMonoid {
using T = int;
static T mempty() { return 0; }
static T mappend(T x, T y) { return x + y; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment