Generate the cata types

This commit is contained in:
Smaug123
2024-02-16 12:50:57 +00:00
parent 1e1176bec5
commit 65d2263a6c
3 changed files with 306 additions and 36 deletions

View File

@@ -17,7 +17,7 @@ type Expr =
| Sequential of Expr list
| Builder of Expr * ExprBuilder
and [<CreateCatamorphism>] ExprBuilder =
and ExprBuilder =
| Child of ExprBuilder
| Parent of Expr

View File

@@ -11,6 +11,33 @@ namespace ConsumePlugin
open WoofWare.Myriad.Plugins
/// Description of how to combine cases during a fold
type ExprCata<'Expr, 'ExprBuilder> =
/// How to operate on the Const case
abstract Const : Const -> 'Expr
/// How to operate on the Pair case
abstract Pair : 'Expr -> 'Expr -> PairOpKind -> 'Expr
/// How to operate on the Sequential case
abstract Sequential : 'Expr list -> 'Expr
/// How to operate on the Builder case
abstract Builder : 'Expr -> 'ExprBuilder -> 'Expr
/// Description of how to combine cases during a fold
type ExprBuilderCata<'Expr, 'ExprBuilder> =
/// How to operate on the Child case
abstract Child : 'ExprBuilder -> 'ExprBuilder
/// How to operate on the Parent case
abstract Parent : 'Expr -> 'ExprBuilder
/// Specifies how to perform a fold (catamorphism) over the type Expr.
type Cata<'Expr, 'ExprBuilder> =
{
/// TODO: doc
Expr : ExprCata<'Expr, 'ExprBuilder>
/// TODO: doc
ExprBuilder : ExprBuilderCata<'Expr, 'ExprBuilder>
}
/// Catamorphism
[<RequireQualifiedAccess>]
module ExprCata =