you are viewing a single comment's thread.

view the rest of the comments →

[–]swyx[S] 4 points5 points  (5 children)

Anjana Vakil with "The Universe in a Single Arrow: A Live Dive into the Lambda Calculus"

Lambda Calculus can be represented with the JS => function. from that, we can do everything a program can do.

  • write the ability to count function applications, get church numerals (numbers that are call-counters)
  • from church numerals, get addition. add n + m by calling a function n times, then m more times.
  • multiplication? call the add n function, m times.
  • booleans/conditionals? sure. var ifthenelse = bool => yay => nay => bool(yay)(nay); var troo = yay => nay => yay; var falz = yay => nay => nay so you can do ifthenelse(falz)(three)(one) // one
  • from booleans, make logical operators! not, and, or in the same way

so we have done natural numbers, booleans, arithmetic, logic and control flow. this is called Church Encoding.

from here: subtract, divide, successor, predecessor, predicates, (in)equality, strings (lists of chars by charcode), lists and list manipulations

more resources:

[–]frugal-grrl 2 points3 points  (4 children)

I didn't understand the "why" of this talk. Why would I want to do everything in lambdas? (Asking seriously, not sarcastically.)

I loved watching this talk because the speaker kicks ass. But I didn't "get" the talk.

I know I don't need this for work, but I want to know why it is interesting. Maybe I don't understand why this is cool because I've never programmed a low-level language? Maybe it is something people use in those? Maybe the "why" of the talk is to get a better understanding of functional programming so I can use Elm or something?

[–]swyx[S] 2 points3 points  (2 children)

i wouldnt go so far as saying that you need this in order to get functional programming. i would say this is far more academic and fundamental than that. the idea of a lot of formal mathematical, logical, and natural philosophy is to start from as small a base of axioms (assumptions) as possible, and derive the entire complexity of the world from that small base. via occam’s razor, if this matches everything we do observe in practice, then it is our best approximation of truth/reality/fundamental laws of the universe. additonally, anything else we can derive that we dont yet observe must also be true. this is the same reason we try to strive for string theory and the Theory of Everything in physics.

so if we can derive all of modern computation then we’ve uncovered some fundamental truth about computation.

make sense? i could go on but im not sure i’m doing this justice.

[–]frugal-grrl 0 points1 point  (1 child)

Yes. So you're saying the exercise is breaking down programming to the minimal building blocks, such as building a counting machine with only functions

[–]jared--w 0 points1 point  (0 children)

Yeah, basically. It actually ends up showing up in a lot of places. Every problem can be represented as "build a language, express the problem as a program in the language, run the program". Of course, most people are more familiar with other patterns (OOP ones in particular).

For example, arithmetic is a very common language we use all the time. It's so common it comes built into JS. You can, however, build other "expression oriented languages" that behave similarly to arithmetic.

In fact, JSX is an expression language and building abstractions inside jsx itself can make things easier to read. One example most people are familiar with is ErrorBoundary. Turns out, its an if then else encoded into JSX (which itself behaves extraordinary similarly to lambda calculus, being only functions nested inside of each other)