Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Recursion Schemes
  3. Matryoshka

Matryoshka

Apache-2.0Scala

A Scala library providing generalized recursion schemes and traversals for fixed point data structures.

GitHubGitHub
821 stars86 forks0 contributors

What is Matryoshka?

Matryoshka is a Scala library that implements generalized recursion schemes—such as folds, unfolds, and traversals—for fixed point data structures. It allows developers to abstract recursion away from business logic, enabling modular and composable transformations on recursive types like trees and lists. The library is based on academic research in functional programming and category theory.

Target Audience

Scala developers working with complex recursive data structures, such as compilers, interpreters, or data transformation pipelines, who want to apply formal recursion schemes for cleaner, more maintainable code.

Value Proposition

Matryoshka provides a comprehensive, type-safe implementation of recursion schemes in Scala, reducing boilerplate and errors associated with manual recursion. It integrates with popular functional libraries like Scalaz and Cats, offering a robust alternative to ad-hoc recursive functions.

Overview

Generalized recursion schemes and traversals for Scala.

Use Cases

Best For

  • Implementing compilers or interpreters with nanopass architectures
  • Transforming abstract syntax trees (ASTs) in functional languages
  • Writing reusable folds and unfolds for complex nested data
  • Applying catamorphisms and anamorphisms to tree-like structures
  • Generalizing recursive algorithms using type classes
  • Learning and applying formal recursion schemes from academic papers

Not Ideal For

  • Projects using imperative or object-oriented Scala without functional libraries like Cats or Scalaz
  • Simple recursive tasks where manual recursion is straightforward and doesn't justify the abstraction overhead
  • Teams with tight deadlines or limited experience in category theory and recursion schemes
  • Environments stuck on Scala versions below 2.12 that cannot support partial unification

Pros & Cons

Pros

Comprehensive Recursion Schemes

Implements a wide range of schemes like cata, ana, para, and histo, enabling expressive and reusable transformations for complex recursive data structures, as detailed in the cheat-sheet and academic references.

Type-Safe Abstractions

Integrates seamlessly with Scala's type system and libraries like Cats/Scalaz through type classes such as Recursive and Corecursive, ensuring compile-time safety and reducing errors in recursive logic.

Modular Design Philosophy

Separates recursion from business logic using algebras and coalgebras, making code more maintainable and composable, as demonstrated in the example where eval algebra is applied independently of the fixed point type.

Academic Rigor and Extensibility

Based on well-researched concepts from functional programming papers, supporting generalized forms like G-algebras and Elgot algebras for advanced use cases, which is highlighted in the generalization section.

Cons

Complex Setup and Configuration

Requires specific Scala compiler settings like '-Ypartial-unification' or a plugin for SI-2712 fix, adding initial setup complexity that can hinder quick adoption.

Steep Learning Curve

Assumes deep familiarity with advanced FP concepts like fixed points, comonads, and monads, making it inaccessible for developers without a background in recursion schemes or category theory.

Performance Trade-Offs

The README admits that direct implementations (e.g., cata) might perform better than generalized versions, and benchmarks are lacking, posing risks for performance-critical applications.

Limited Ecosystem and Documentation

With only Quasar listed as a user and reliance on academic papers for guidance, the library has a niche community and fewer practical examples compared to mainstream alternatives.

Frequently Asked Questions

Quick Stats

Stars821
Forks86
Contributors0
Open Issues14
Last commit6 years ago
CreatedSince 2016

Tags

#functional-programming#fixed-point#category-theory#recursion-schemes#algebraic-data-types#scalaz#scala#algebra#type-classes#cats#fold

Built With

C
Cats
S
Scala

Included in

Recursion Schemes1.3k
Auto-fetched 7 hours ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub