How Type Variance fits into Category Theory

Category theory

Sets

(f◦g)◦h = f◦(g◦h)

Groups

Monoids

Others

Category

Is there a category of categories?

Objects are not containers!

Is there a category of functors?

Type Variance

  • yes, a list of horses is a list of animals
  • no, a list of horses is completely different from a list of animals
  • no, actually a list of animals is a list of horses.

How type variance fits into category theory

  • a covariant functor if T is covariant as a type parameter (we will write F[+T])
  • a contravariant functor if T is contravariant as a type parameter (we will write F[-T])
  • no functor (sadly) if T is invariant (we simply write F[T]).
Function[Function[T, Boolean], T]

Conclusion

--

--

--

Mathematician, Scala enthusiast, father of two.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Rando- Arduino Controlled Randomly Sketching Robot

Iterator Methods in Ruby

The Penguin’s Guide to Scrum

CSS Grids — How Everyone Has Been Building The Web Wrong Before 2018

Ending educational poverty

Configure LB(haproxy) using Ansible-Roles on AWS.

Everything you need to know about Headings in WCAG

a lady working on a laptop. In text: Headings in WCAG

Retro CSS Frameworks&Libraries&Themes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Antoine Doeraene

Antoine Doeraene

Mathematician, Scala enthusiast, father of two.

More from Medium

Petri Net — Simplified

Exploring the Collatz conjecture on the Scala REPL

Some far-fetched thoughts on “inverting” algorithms

Computational Algebra and Number Theory with Scala: Introduction