Edit. For example, let's take 'catamorphism'. Read the Wikipedia entry [0] and it's a seemingly never ending jungle of more and more abstract terms. Homomorphism, initial algebra, F-algebra, endomporphism. This easy, let's see what an F-algebra is [1] and we'll be on our way soon. "If C is a category, and F: C → C is an endofunctor of C, then an F-algebra is a tuple (A, α), where A is an object of C and α is a C-morphism F(A) → A.". Oh my God, this is hopeless.
Or, find a good description, with examples [2]. A 'catamorphism' card, abbreviated from [2]:
Catamorphism
A function that “collapses” a recursive type into a new value based on its structure. Visitor pattern.
Define a sum type Gift:
type Book = {title: string; price: decimal}
type Gift =
| Book of Book
| Boxed of Gift
Define a 'description' function over Gift: let rec description gift =
match gift with
| Book book ->
sprintf "'%s'" book.title
| Boxed innerGift ->
sprintf "%s in a box" (description innerGift)
Parametrize the function, creating a 'catamorphism': let rec cataGift fBook fBox gift =
match gift with
| Book book ->
fBook book
| Boxed innerGift ->
let innerGiftResult = cataGift fBook fBox innerGift
fBox innerGiftResult
Refactor your 'description' function to use a 'catamorphism': let descriptionUsingCata gift =
let fBook (book:Book) =
sprintf "'%s'" book.title
let fBox innerText =
sprintf "%s in a box" innerText
// call the catamorphism
cataGift fBook fBox gift
[0] https://en.wikipedia.org/wiki/Catamorphism[1] https://en.wikipedia.org/wiki/F-algebra
[2] https://fsharpforfunandprofit.com/posts/recursive-types-and-...