Published
Edited
Jan 10, 2020
Insert cell
Insert cell
{
var ZERO = transform => start_value => start_value
}
Insert cell
{
var ONE = transform => start_value => transform(start_value)
}
Insert cell
Insert cell
{
var TWO = transform => start_value => transform(transform(start_value))
}
Insert cell
Insert cell
{
var ZERO = transform => start_value => start_value;
var SUCC =
qtyFn =>
transform =>
start_value => transform(qtyFn(transform)(start_value));
}
Insert cell
Insert cell
{
var ZERO = transform => start_value => start_value;
var SUCC =
qtyFn =>
transform =>
start_value => transform(qtyFn(transform)(start_value));

var ONE = SUCC(ZERO);
var TWO = SUCC(ONE);
var THREE = SUCC(TWO);
var FOUR = SUCC(THREE);
var FIVE = SUCC(FOUR);
var SIX = SUCC(FIVE);
var SEVEN = SUCC(SIX);
var EIGHT = SUCC(SEVEN);
var NINE = SUCC(EIGHT);
var TEN = SUCC(NINE);
}
Insert cell
Insert cell
{
// Define the increment and decrement reification functions
var adder = val1 => val2 => val1 + val2;
var incr = adder(1);
var decr = adder(-1);

// Starting from ZERO and SUCCESSOR, define some abstract quantity functions
var ZERO = transform => start_value => start_value;
var SUCC =
qtyFn =>
transform =>
start_value => transform(qtyFn(transform)(start_value));

var ONE = SUCC(ZERO);
var TWO = SUCC(ONE);
var THREE = SUCC(TWO);

// Using the abstract quantity function TWO, apply the SUCC function twice to a starting value of THREE
// In other words, this operation represents the behaviour of performing the ADD operation 2 + 3
// The resulting function encodes the behaviour needed to generate the value FIVE
var FIVE = TWO(SUCC)(THREE);

return {
// Just to prove that the behaviour of our abstract quantity functions is correct,
// reify these functions by passing the transformation function "incr" and a starting value of 0.
// This causes the relevant counting numbers to be generated
reify_TWO : TWO(incr)(0)
, reify_THREE : THREE(incr)(0)
, reify_FIVE : FIVE(incr)(0)

// Apply the decr function three times to a starting value of 7
// In other words, subtract 3 from 7
, reify_seven_minus_three : THREE(decr)(7)
}
}
Insert cell
Insert cell
// How many times will a quantity function call its transformation function?
magnitude = qtyFn => qtyFn(lib.incr)(0)
Insert cell
{
// What's the magnitude of these abstract quantity functions?
return {
magnitude_of_ZERO : magnitude(lib.ZERO)
, magnitude_of_THREE : magnitude(lib.THREE)
, magnitude_of_third_SUCC_of_TWO : magnitude(lib.TWO(lib.SUCC)(lib.THREE))
}
}
Insert cell
Insert cell
NUMBER = isPositive => qtyFn => lib.PAIR(isPositive)(qtyFn)
Insert cell
Insert cell
PLUS_ONE = NUMBER(lib.TRUE)(lib.ONE)
Insert cell
MINUS_ONE = NUMBER(lib.FALSE)(lib.ONE)
Insert cell
Insert cell
is_pos = number => to_boolean(IS_POS(number))
Insert cell
IS_POS = number => lib.HEAD(number)
Insert cell
Insert cell
to_boolean = bool => bool(true)(false)
Insert cell
Insert cell
{
return {
abstract_sign_ONE : IS_POS(PLUS_ONE)
, abstract_sign_MINUS_ONE : IS_POS(MINUS_ONE)

, reified_sign_ONE : is_pos(PLUS_ONE)
, reified_sign_MINUS_ONE : is_pos(MINUS_ONE)
}
}
Insert cell
Insert cell
ABS = number => lib.TAIL(number)
Insert cell
abs = number => magnitude(ABS(number))
Insert cell
{
return {
abstract_abs_of_ONE : ABS(PLUS_ONE)
, abstract_abs_of_MINUS_ONE : ABS(MINUS_ONE)

, reified_abs_of_ONE : abs(PLUS_ONE)
, reified_abs_of_MINUS_ONE : abs(MINUS_ONE)
}
}
Insert cell
Insert cell
_ZERO = NUMBER(lib.TRUE)(/* Hmmm, what value goes here? */)
Insert cell
Insert cell
ZERO_MAGNITUDE = transform => start_value => start_value
Insert cell
ZERO = NUMBER(lib.TRUE)(ZERO_MAGNITUDE)
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more