# What “Hylomorphic” Means

Way back when, now nearly invisible through the mists of time, I made a decision to name my fledgling business “Hylomorphic”. Where did that idea come from?

First of all, it’s just a cool-sounding word that’s a decently unique identifier for a new company. (I know certain people who hate when I qualify “unique”, but oh well.)

Second of all…it’s complicated.

## A Tale of Two Algebras

It’s really “A Tale of an Algebra and its Coalgebra”, but that’s not as pithy. We only need F-algebras here, and so instead of getting into (and misrepresenting) the category theory behind this, I’ll just encourage you (and my future self) to read up on that, and give some code. We define an F-algebra

type Algebra f a = f a -> a

and its F-coalgebra

type Coalgebra f a = a -> f a

just like in Control.Functor.Algebra.

## A Tale of Two Morphisms

Also just like with algebras, I’ll be glossing over what “morphism” means. Let’s say it’s a way for us to transform something into something else, while keeping around some of the structure of the original thing. Vague enough?

There are two kinds of morphisms we need here. The first is a “catamorphism”, commonly called a fold. Recall this definition of sum:

sum = foldl' (+) 0

This expresses the key idea behind catamorphisms. We’re taking a big set of results (list of numbers), and reducing it down to one single result (single number) at the end.

We need one more thing to get started: functor fixpoints.

newtype Fix f = In { out :: f (Fix f) }

We define catamorphisms like this:

cata :: Functor f => Algebra f a -> Fix f -> a
cata f = f . fmap (cata f) . out

We can also define something called an “anamorphism”. It works the opposite way: it takes a single thing and unspools it into a big list of results. Commonly known as unfold.

ana :: Functor f => Coalgebra f a -> a -> Fix f
ana f = In . fmap (ana f) . f

## A Tale of A Bad Analogy to Hegelian Dialectics

So we have our thesis, our unfold, our anamorphism, which builds up a set of results. Then we have our antithesis, our fold, our catamorphism, which takes the set of results and combines them down into one final result. Seems like our synthesis, our unfold-then-fold, our hylomorphism, follows pretty naturally.

A hylomorphism is an anamorphism followed by a catamorphism.1

hylo :: Functor f =>
Algebra g b ->
(forall c. f c -> g c) ->
Coalgebra f a -> a -> b
hylo f e g = f . e . fmap (hylo f e g) . g 

## A Tale of Abusing Greek Suffixes

So we have the word “hylomorphism”. How do we get “hylomorphic”?

Simple! We take the Greek suffix “-ic” to make words adjectives and swap it in. Why? It sounds cooler, and naming something an “-ism” is a recipe for disaster.

## Final Note

This is not the way I ever actually explain the name to people who ask. (God help them if I ever started doing that….) A more realistic version could be: “It means something that builds up a big set of results and then condenses those down to one final result.”