Type, shape and signature
An effective way to think about coding is from the the focal points of variable type, variable shape, and function signature. From this perspective we can ask questions about assignments (=) and operations (+/-) with precision.
Data have general types, specific shapes, and arbitrary size
Consider the task of adding up an "array of arrays of Integers". In order to add up an array of array of Integers (think of Integers as boxed ints) , we need to be able to describe the nested shape. The innermost array holds a value of type Integer
, thus:
Inside out:
- type of
data[i][j]
is an Integer - type of
data[i]
is an Array - type of
data
is an Array // outermost
Outside in:
- type of
data
is an Array // outermost - type of
data[i]
is an Array - type of
data[i][j]
is an Integer
The shape of data is "an array of an array of Integers"
The shape of data[i]
is "an array of Integers"
The shape of data[i][j]
is "an Integer"
The shape of Integer is an "object of int" // boxed int
The shape of int is a primitive.
You should always be able to trace your nested type down to a primitive. Functions transform data and create side effects. They are defined by their function signature. The main point is AKYT: Always Know Your Types.
Advanced references
The paper Type Systems by Luca Cardelli is a good place to learn the formal language of type systems. The paper Proposition as Types by Philip Wadler is a popular technical summary of the theory of computation. And the paper Physics, Topology, Logic and Computation: A Rosetta Stone, by John Baez and Mike Stay really pulls the room together.