Skip to content

Instantly share code, notes, and snippets.

@slavaschmidt
slavaschmidt / recursion schemes.scala
Created February 13, 2019 19:32 — forked from monaddle/recursion schemes.scala
Recursion schemes implemented in Scala using Matroyshka. They don't all make sense or anything, but they compile and run. lo
package prestwood
// Examples of recursion scheme implementations using matroysha. Mostly they're not that useful,
// and I really only got three tricks down, but they're good tricks:
// 1. Collect information across an AST using a Writer monad
// 2. Modify AST nodes in place
// 3. Annotate AST nodes with arbitrary types

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x