4 ms·
Most of the jargon denotes straightforward definitions. Pick the top-most frequent three terms, e.g. monad, monoid, applicative, write down the definition + a s
by pacala 6y ago
Most of the jargon denotes straightforward definitions. Pick the top-most frequent three terms, e.g. monad, monoid, applicative, write down the definition + a small example on a card, lather rinse repeat a few times and you're golden.
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 https://en.wikipedia.org/wiki/Catamorphism
[1] https://en.wikipedia.org/wiki/F-algebra https://en.wikipedia.org/wiki/F-algebra
[2] https://fsharpforfunandprofit.com/posts/recursive-types-and-folds/#catamorphisms https://fsharpforfunandprofit.com/posts/recursive-types-and-...
- yodsanklai 6y agoI'd argue that 99.9% of OCaml programmers have never heard of the term "catamorphism"! Still cool to know there's a name for it, but I wouldn't write in a code review "why don't you refactor your description function using a catamorphism".
- zozbot234 6y ago> Read the Wikipedia entry [0] and it's a seemingly never ending jungle of more and more abstract terms. Yup, category theory is often called "general abstract nonsense" precisely because it manages to talk about many disparate parts of math (or programming!) in a way that purposely avoids any reference to the specific. To usefully interpret the above, you specifically need to know that your domain often uses the category (C) of types (as objects) and functions (as morphisms), and that this category features certain generic types (such as Option, List, Array etc.) as endofunctors - and then literally plug all of those into the definition and work out the result. It's exactly the difference between (in an elementary context) a word problem, vs. the general theory of equations of type foo which could be used to solve any number of word problems - except replicated at a higher level.
- pacala 6y agoI like the way you frame CT. Never got too deep down this rabbit hole, the terminology is just too atrocius. I wonder though how useful it is in practice. It is easier for me to take a formula and generalize it among one dimension at a time as the needs arise, see the catamorphism example above. As opposed to correctly divine 5-10-15 very specific concretizations of an uber-abstract scheme to arrive to the same result. Echoes of premature abstraction. Perhaps the world lacks CT for dummies. Teach it in primary school. New Math was not aggressive enough ;)