Skip to content

Instantly share code, notes, and snippets.

@witt3rd
Last active August 26, 2018 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save witt3rd/397114c6009ccf8930d1b2bcbb2f8f31 to your computer and use it in GitHub Desktop.
Save witt3rd/397114c6009ccf8930d1b2bcbb2f8f31 to your computer and use it in GitHub Desktop.

Category Theory

Data

  • Objects
  • Arrows
    • Source object
    • Target object
  • Rules
    • Identity
      • Arrow where source = target
    • Composition
      • if f: X -> Y and g: Y -> Z, then h: X -> Z = g . f
    • Associativity
      • if f: A -> B and g: B -> C and h: C -> D, then (h . g) . f = h . (g . f)

Monoid

Category with a single object.

trait Monoid[A] {
  def identity: A
  def compose(x: A, y: A): A
}
class Monoid a where
    mempty  :: a
    mappend :: a -> a -> a

Functors

Objects that implement map.

class Functor f where  
    fmap :: (a -> b) -> f a -> f b  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment