Free Monoids: Monoids for Anything!

Adam Rosien @arosien
Inner Product LLC inner-product.com

13 Mar 2020

Monoid

Int

String

List

A?

(⊙_◎)

A hint

What do you get when you combine an A with an A?

Two As!

ಠ‿ಠ

Another hint

|

||

|||

||||

⋮

“The Trick”

a1

(a1, a2)

(a1, a2, a3)

(a1, a2, a3, a4)

⋮

List(a1, ..., aN)

“The Trick”

“The Trick”

“The Trick”

Free All the Structures!

Free Boolean Algebra

Free Functor

Free Monad

Summary

  • Free structures let you add structure to any type.
  • The trick is to delay the operations of a structure, converting them to data.
  • They are implemented as reified typeclasses, plus an injector (in).
  • You can always go in, but you can’t always go out.

Thank you!

Adam Rosien @arosien

Inner Product LLC inner-product.com

Hire us to ☝︎
teach / mentor / join
your team!


References and Links: