Published
Edited
Jan 10, 2020
Insert cell
Insert cell
SUCC_PAIR = pair => lib.PAIR(pair(lib.FALSE))(lib.SUCC(pair(lib.FALSE)))
Insert cell
Insert cell
p00 = lib.PAIR(lib.ZERO)(lib.ZERO)
Insert cell
p01 = SUCC_PAIR(p00)
Insert cell
p12 = SUCC_PAIR(p01)
Insert cell
{
return {
"head" : lib.to_integer(p01(lib.TRUE)),
"tail" : lib.to_integer(p01(lib.FALSE))
}
}
Insert cell
{
return {
"head" : lib.to_integer(p12(lib.TRUE)),
"tail" : lib.to_integer(p12(lib.FALSE))
}
}
Insert cell
Insert cell
// The predecessor of a quantity function of magnitude n can be found by SUCC_PAIR as the transformation
// function, and PAIR(ZERO)(ZERO) as the starting value.
// This will return a number PAIR in which we are interested only in the first number.
// Therefore, pass the resulting pair to TRUE in order to extract the required value.
PRED = qtyFn => qtyFn(SUCC_PAIR)(lib.PAIR(lib.ZERO)(lib.ZERO))(lib.TRUE)
Insert cell
// The predecessor of seven is...
lib.to_integer(PRED(lib.SEVEN))
Insert cell
Insert cell
SUBTRACT = qtyFn1 => qtyFn2 => qtyFn2(PRED)(qtyFn1)
Insert cell
// 8 minus 5 is...
lib.to_integer(SUBTRACT(lib.EIGHT)(lib.FIVE))
Insert cell
// And 5 minus 8 is...
lib.to_integer(SUBTRACT(lib.FIVE)(lib.EIGHT))
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