Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created August 9, 2013 19:38
Show Gist options
  • Select an option

  • Save aamedina/6196541 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6196541 to your computer and use it in GitHub Desktop.
;; so now that you can intuitively understand the notion of a "Category", let's talk about Streams.
;; Streams are a category invented to optimize the execution of functions performed on Lists.
;; Categories are like Types in a way. We can have Real numbers, Complex numbers, Sets, Integers, Lists, etc.
;; They all have different properties. Some are more general, and some are less general.
;; When we can create a function that maps an element of one Category A to another Category B in
;; a way that preserves the "structure" of the category, we have shown that there is some morphism between them.
;; a "morphism" is just a fancy way of saying mapping function, (map)!
;; we create morphisms all the time in functional programming.
(map str #{1 2 3 4 5})
("1" "2" "3" "4" "5")
(map identity '(0 1 2))
(0 1 2)
(map squared [0 1 2])
(0 1 4)
;; etc
;; There are many different types of morphisms. Without going into too much boring detail, the most important ones for our purposes
;; are morphisms that are isomorphisms - meaning that the structure (morph) is equivalent (iso)
;; Isomorphisms are like the mathematical equivalent of analogies. And yes, that sentence does read sort of recursively. :P
;; In essence, since categories have properties - likes Sets and Lists, if there exists an isomorphism between Category A and B, then
;; all properties of Category A are true about Category B and visa versa. You can even say that perhaps they're equivalent in a manner of speaking,
;; even though they may look different, and are used in different ways.
;; Without knowing about this, we actually created isomorphisms earlier!
;; remember
(def squared-cubed (comp squared cubed))
(defn h
[x]
(* (* x x x) (* x x x)))
;; This functions structure can be considered isomorphic to another function which simply computed the same thing, but directly.
;; see how complicated defining the squared result of the cube of some number is when not using function composition?
;; Function composition allows us to "structurally preserve" some procedure or data structure and yet reason about it
;; in a higher level way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment