|
|
|
|
|
by pinopinopino
2426 days ago
|
|
Neat, but I think it would have even more interesting to use church encoding for your numbers. It would have shown some of the wonderful inhabitants this seemingly simple structure can lead to :) It really is a small universe. |
|
a church¹ encoding of booleans:
just says that, given a boolean value, you can choose one of two control flow paths, i.e. do or using the church-encoded version: a product type just means "you can do stuff using the parts", i.e. and that just means you can do e.g. or, using the church encoded version it's like the ultimate "inversion of control" - the values are driving the program by calling the continuations passed to them! tbh i always get chills when i think about this, bc it just seems like such a deep thing... lambdas really are the ultimate everything, especially values :)(and now, a handwavy, possibly rambling conclusion)
to me, this embodies the fact that booleans, numbers and other values have no inherent meaning - what matters about them is that we can, via pattern matching or something else, distinguish e.g. True and False, or 0 and 13 and 725, and do different things. like, the bits we use to represent binary numbers have no meaning either; what matters about a particular pattern of bits is how it changes the execution of a program relative to other patterns of bits that could be in its place.
---
¹ with some added () to work in non-lazy languages and to highlight that the type `Bool` is just the sum `Unit + Unit`