Project
The user-supplied bridge between a recursive type S and one layer of its pattern functor F[_] — the correspondence the typed recursion schemes (cata / ana / hylo, in the schemes module) and the Plated.fromBasis derivation are built on.
A pattern functor replaces S's recursive positions with a type parameter:
enum Bin: case Leaf(n: Int); case Branch(l: Bin, r: Bin)
enum BinF[A]: case LeafF(n: Int); case BranchF(l: A, r: A) // recursion → A
Project peels one layer off (S => F[S]), Embed glues one layer back on (F[S] => S). A driver then walks F with the user's Traverse[F], so algebras pattern-match F's named constructors (case BranchF(l, r) => l + r) instead of indexing an erased vector.
Unlike the F type itself (which the user must write — Scala-3 macros emit terms, not type definitions), Project/Embed are ordinary instances, expected hand-written (droste's model).
'''Coherence laws''' (the S↔F correspondence is hand-maintained and NOT compiler-checked — a swapped or non-exhaustive mapping is a silent bug, so these are exercised by the typed-scheme law suite):
embed(project(s)) == s // round-trip through one layer of S
project(embed(fs)) == fs // round-trip through one layer of F
Attributes
- Source
- Basis.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-