Functional Programming Analogy

16 Apr 2014 . concepts #analogies #programming

Imagine a brand new robot which can follow basic instructions and learn new stuff.

Instructions

  1. Find cloth / broom
  2. Pick it up
  3. Dust surfaces

Functions

  1. Clean object means follow the above instructions for given object
  2. Clean door
  3. Clear window …

Recursion

  1. Clean object means if object has smaller objects, clean each small object else clean object
  2. Clean room

Higher order functions

  1. Begin task means perform the task for all objects
  2. Spraying water on object means to sprinkle water on object
  3. Drying object means to clean object
  4. Begin spraying
  5. Begin drying

Note: doesn’t include closures.