Hacker News new | ask | show | jobs
by edflsafoiewq 542 days ago
They're just a nice way of writing equations between functions (or other things that compose like functions).

This is a picture of a function f that takes inputs from A and produces outputs in B

    f
  A → B
and this diagram

    f
  A → B
    ↘ ↓ g
   h  C
just means g ∘ f = h, ie. doing f then g is the same as doing h. Since you write the domain and codomain of each function, it makes it easier to see when the functions can compose (ie. when it type checks).

Because paths through a diagram themselves compose like functions do, this notation turns out to be very natural. For example, associativity is inherent in the notation: A→B→C→D is the only way to express the composition of three functions, you can't even write the difference between (f∘g)∘h and f∘(g∘h).

2 comments

> For example, associativity is inherent in the notation: A→B→C→D is the only way to express the composition of three functions, you can't even write the difference between (f∘g)∘h and f∘(g∘h).

It's only unwritable in a linear picture. If you wanted to make associativity visible, then you could express it in terms of commutativity using arrows that hop over nodes.

is it common/allowed to have set types instead of the A/B/C symbols? or the A/B/C simply implies the sets differ, because functions did something to them? I mean - can you write N, R, C... ?

otherwise - very very very neat explanation, thanks a thousand times.