Latest / CyberSecurity Summary / An Introduction to Functional Programming Through Lambda Calculus
Transcript
- 0:00Speaker 1: So how often do you actually think about the invisible
- 0:03Speaker 1: architecture of the Internet when you do something really simple,
- 0:08Speaker 1: like say a Google search.
- 0:10Speaker 2: I mean probably never, right, You just want your answer
- 0:12Speaker 2: right exactly.
- 0:13Speaker 1: You type in a query, hit enter, and boom, billions
- 0:16Speaker 1: of records are just sifted through to hand you a
- 0:18Speaker 1: result in literally milliseconds. We treat it like magic.
- 0:21Speaker 2: Oh absolutely, But you know, peaking under the hood reveals
- 0:24Speaker 2: something entirely unexpected.
- 0:26Speaker 1: Yeah, you won't just find like miles of fiber optic
- 0:29Speaker 1: cables or massive server farms. You actually find this intense,
- 0:33Speaker 1: unresolved mathematical debate from the nineteen.
- 0:36Speaker 2: Thirties and the remnants of a totally failed nineteen eighties
- 0:39Speaker 2: software revolution.
- 0:40Speaker 1: Too, which is wild and well. It all points to
- 0:44Speaker 1: a completely alien philosophy regarding how computers should solve problems
- 0:47Speaker 1: in the first place.
- 0:48Speaker 2: It really is a fundamental shift in logic. I mean,
- 0:50Speaker 2: anybody who has written even a few lines of say
- 0:53Speaker 2: Python or JavaScript, they intuitively understand computers as machines that
- 0:58Speaker 2: just follow sequential instructions.
- 1:00Speaker 1: Like step one, do this, step two, check that.
- 1:02Speaker 2: Exactly, step three, update this counter. But there is an
- 1:05Speaker 2: entire parallel universe of programming that completely abandons that step
- 1:09Speaker 2: by step logic, basically rips the clock out of the
- 1:11Speaker 2: computer entirely.
- 1:13Speaker 1: And we are dissecting that universe today through our deep
- 1:15Speaker 1: dive into Greg Michaelson's book An Introduction to Functional Programming
- 1:20Speaker 1: through Lambda.
- 1:20Speaker 2: Calculus, a fantastic albeit heavy.
- 1:23Speaker 1: Read, oh definitely heavy. We're specifically looking at his foundational
- 1:27Speaker 1: chapters and that rather candid twenty eleven Prephecy wrote, and
- 1:31Speaker 1: you know, the objective here isn't just to learn a
- 1:33Speaker 1: new coding language.
- 1:34Speaker 2: No, no, it's way bigger than that, right.
- 1:35Speaker 1: It's to understand what functional programming actually is mechanically, like,
- 1:40Speaker 1: why this incredibly dense, seventy five year old math concept
- 1:44Speaker 1: breaks our standard rules of computing, and.
- 1:46Speaker 2: How it quietly became the load bearing pillar for the
- 1:49Speaker 2: biggest distributed systems on the planet.
- 1:51Speaker 1: So to appreciate this functional approach, we really have to
- 1:54Speaker 1: isolate the underlying flaw in how we normally write software.
- 1:58Speaker 2: Yeah, we do so. The most commercial code is written
- 2:01Speaker 2: in what we call imperative languages. So thinks ce Java, Python,
- 2:06Speaker 2: usual suspects, right, and they are built on this concept
- 2:09Speaker 2: of mutating state. You issue an imperative command to change
- 2:13Speaker 2: the value of a.
- 2:13Speaker 1: Variable, like giving the computer in order.
- 2:16Speaker 2: Exactly, you tell the system, hey, X is currently five,
- 2:19Speaker 2: but now I command you to make x equal to.
- 2:22Speaker 1: Six, which I mean that seems entirely logical to me.
- 2:25Speaker 1: We are commanding the machine to update its memory.
- 2:28Speaker 2: It does seem logical, well, until you try to do
- 2:31Speaker 2: a million things at once.
- 2:32Speaker 1: Aw the scale issue.
- 2:34Speaker 2: Right. Because imperative programming is entirely reliant on state mutation,
- 2:39Speaker 2: it creates this terrifying vulnerability known as a side effect.
- 2:42Speaker 1: Okay, let's unpack this. Yeah, what exactly does a side
- 2:45Speaker 1: effect look like in action?
- 2:46Speaker 2: Well, imagine you have a variable tracking a user's bank balance, okay,
- 2:51Speaker 2: and thread A is reading that balance to display it
- 2:53Speaker 2: on a screen for you. But at that exact millisecond,
- 2:56Speaker 2: thread B in the background mutates that variable to process
- 2:59Speaker 2: a subscription fee.
- 3:00Speaker 1: Oh wow, so thread A suddenly grabs the wrong number.
- 3:03Speaker 2: Exactly. In an imperative program the state is the shared,
- 3:07Speaker 2: constantly shifting battleground. Anyone can change it, so.
- 3:10Speaker 1: It's basically like a chalkboard where you keep erasing and
- 3:13Speaker 1: rewriting a running tally, and if someone erases it while
- 3:16Speaker 1: you're looking away, you're messed up.
- 3:18Speaker 2: That is a perfect analogy.
- 3:20Speaker 1: Yes, so functional programming then basically removes the.
- 3:24Speaker 2: Eraser precisely, it takes the eraser completely out of the equation.
- 3:28Speaker 1: In this paradigm, a variable isn't a storage container you
- 3:32Speaker 1: can just overwrite. It's more like a prominent mathematical binding.
- 3:36Speaker 1: It's like carving a number into a stone tablet.
- 3:39Speaker 2: I like that carved in stone. So once X is
- 3:42Speaker 2: tied to the value of five, it is five forever.
- 3:45Speaker 1: And if you want a new state, like if the
- 3:47Speaker 1: bank balance changes.
- 3:48Speaker 2: You don't mutate X. You have to evaluate a completely
- 3:51Speaker 2: new expression that outputs a new value. You carve a
- 3:54Speaker 2: new tablet.
- 3:55Speaker 1: So you never actually change the data.
- 3:56Speaker 2: Nope, you only pass it through functions to create new data.
- 4:00Speaker 1: But how does that actually help with the bank balance problem.
- 4:02Speaker 2: Well, that permanent binding changes the literal physics of the software.
- 4:06Speaker 2: Because you never erase or mutate anything. You completely eliminate
- 4:11Speaker 2: those side effects we talked about.
- 4:12Speaker 1: Oh, because nothing can sneak in and change the data
- 4:14Speaker 1: behind your back exactly.
- 4:16Speaker 2: A function in this world is mathematically pure. It receives
- 4:19Speaker 2: an input, does its calculation, and returns an output.
- 4:23Speaker 1: It's totally isolated.
- 4:24Speaker 2: Right, it's a hermetically sealed unit of logic. It cannot
- 4:27Speaker 2: secretly reach outside of itself and mess with a global
- 4:30Speaker 2: counter or access a database in the background.
- 4:33Speaker 1: Okay, hold on, I understand the security of a hermetically
- 4:36Speaker 1: sealed function. But and here's the catch. In a physical machine,
- 4:41Speaker 1: things physically have to happen one after another in.
- 4:44Speaker 2: Our standard view of time.
- 4:45Speaker 1: Yes, right, If I write a program in an imperative language,
- 4:49Speaker 1: the order of my commands is life. Rather, if I
- 4:52Speaker 1: swap lines of code, the program.
- 4:54Speaker 2: Just crashes because line three depends on the mutated state
- 4:57Speaker 2: created by line two exactly.
- 4:59Speaker 1: Sequence dictates.
- 5:00Speaker 2: Well, that's the imperative prison. Right. You are basically chained
- 5:03Speaker 2: to time. But because functional programming prohibits mutation entirely, time
- 5:08Speaker 2: loses its authority over the code. Wait really, yeah, execution
- 5:13Speaker 2: order simply ceases to matter.
- 5:14Speaker 1: That sounds physically impossible. How can a machine process logic
- 5:19Speaker 1: without a sequence. Doesn't the program need to know what
- 5:22Speaker 1: to execute first to feed into the next step.
- 5:25Speaker 2: It relies on this really elegant mathematical principle called the
- 5:29Speaker 2: Church Rosser theorem. Okay, way on me, Let's look at
- 5:31Speaker 2: a basic arithmetic expression, say two plus three in parentheses
- 5:36Speaker 2: multiplied by four plus five in parentheses.
- 5:40Speaker 1: Right.
- 5:41Speaker 2: Because these are pure values with no hidden side effects,
- 5:44Speaker 2: it genuinely does not matter if you calculate the two
- 5:47Speaker 2: plus three first or if you calculate the four plus five.
- 5:50Speaker 1: First, because they don't impact each other.
- 5:51Speaker 2: Exactly, you will arrive at forty five either way.
- 5:54Speaker 1: Okay, that makes sense in a small scale.
- 5:56Speaker 2: Well, the church Rosso theorem mathematically proves that if a
- 6:00Speaker 2: functional program terminates, it will yield the exact same final
- 6:05Speaker 2: result regardless of the order in which its sub expressions
- 6:08Speaker 2: are evaluated.
- 6:09Speaker 1: Ah So, because the functions are pure, they just don't
- 6:11Speaker 1: care who finishes first. They aren't waiting on some global
- 6:14Speaker 1: variable to change somewhere else.
- 6:16Speaker 2: What's fascinating here is what happens when you scale that
- 6:19Speaker 2: concept up. You suddenly see why massive tech companies like
- 6:23Speaker 2: Google and Amazon care deeply about this.
- 6:25Speaker 1: Oh, because if execution order doesn't matter, you aren't limited
- 6:29Speaker 1: to running your program on just one processor exactly.
- 6:32Speaker 2: You can take a massive functional program, shatter it into
- 6:35Speaker 2: a million independent pieces, and farm those pieces out to
- 6:39Speaker 2: tens of thousands of cheap servers simultaneously.
- 6:42Speaker 1: That is incredible, and Michaelson actually notes this in his
- 6:45Speaker 1: twenty eleven preface right that Google's map produce framework is
- 6:49Speaker 1: built directly on these concepts.
- 6:51Speaker 2: He does, map reduce is the engine that made their
- 6:54Speaker 2: search indexing so incredibly fast.
- 6:56Speaker 1: How does that actually map to functional programming? Though?
- 6:59Speaker 2: So the map function processes data independently across thousands of
- 7:03Speaker 2: machines without any shared state, and then the reduced function
- 7:06Speaker 2: aggregates all those pure outputs.
- 7:08Speaker 1: So there are no locks, no race conditions, no side effects, none.
- 7:12Speaker 2: It's perfectly parallel.
- 7:13Speaker 1: Okay, I see how that enables massive parallel processing for
- 7:17Speaker 1: a tech giant. But let me challenge the everyday utility
- 7:20Speaker 1: of this for a second.
- 7:21Speaker 2: Go for it.
- 7:22Speaker 1: If I have no sequence and I'm not allowed to
- 7:24Speaker 1: mutate a variable, how do I actually do something repetitive?
- 7:28Speaker 1: How do I iterate?
- 7:29Speaker 2: Give me an example?
- 7:30Speaker 1: Okay, say I want to search through a list of
- 7:32Speaker 1: a million log files to find one specific error code.
- 7:36Speaker 1: In normal imperative code, I write a standard for loop.
- 7:40Speaker 1: I use a counter variable what's called I, and I
- 7:43Speaker 1: mutate I from one to a million, checking the list
- 7:46Speaker 1: each time.
- 7:47Speaker 2: The classic approach.
- 7:48Speaker 1: Sure, right, So how do you loop without a counter.
- 7:51Speaker 2: Well you don't. You don't use loops at all.
- 7:53Speaker 1: Wait what no loops?
- 7:54Speaker 2: No loops. Loops inherently require state mutation. You have to
- 7:57Speaker 2: update that counter instead. Functional programming relies on recursion.
- 8:02Speaker 1: Okay, recursion, how does that work? In this context?
- 8:05Speaker 2: You have a function that processes the very first item
- 8:07Speaker 2: in the list, just the first one. If it's not
- 8:10Speaker 2: the error code you're looking for. The function calls a
- 8:12Speaker 2: brand new, pristine copy of itself. Oh, I see it,
- 8:15Speaker 2: and it passes the remainder of the list to that
- 8:17Speaker 2: new copy.
- 8:18Speaker 1: Okay, let me make sure I'm visualizing this right. So
- 8:20Speaker 1: instead of one runner running a million laps and checking
- 8:23Speaker 1: a stopwatch every time, you basically have a relay race
- 8:26Speaker 1: with a million distinct runners.
- 8:28Speaker 2: Yes, that's a great way to put it.
- 8:30Speaker 1: Each runner only runs one step, looks at the data,
- 8:33Speaker 1: and passes the baton to a totally new clone of themselves.
- 8:37Speaker 2: That's a very solid way to visualize it. Every recursive
- 8:40Speaker 2: call creates a completely fresh execution context. You never change
- 8:45Speaker 2: the original list.
- 8:46Speaker 1: You just keep peeling off the first element and passing
- 8:49Speaker 1: the rest for.
- 8:49Speaker 2: Us exactly, and this forces a radically different approach to
- 8:53Speaker 2: data structures as a whole because there's no assignment. There
- 8:56Speaker 2: are no arrays where you can just tweak element number four.
- 9:00Speaker 1: Right, because you can't mutate it.
- 9:02Speaker 2: You have to explicitly pass entire nested structures through these
- 9:06Speaker 2: recursive chains, and you rely heavily on abstraction to keep
- 9:10Speaker 2: the logic clean.
- 9:11Speaker 1: Which brings us to chapter two. Michaelson dedicates that whole
- 9:15Speaker 1: chapter to the concept of abstraction, and it seems really
- 9:18Speaker 1: pivotal here.
- 9:19Speaker 2: It is without abstraction, this whole system collapses under its
- 9:23Speaker 2: own weight.
- 9:23Speaker 1: Because abstraction isn't just about hiding complexity, right, It's about
- 9:27Speaker 1: shifting from concrete values to generalized rules exactly.
- 9:32Speaker 2: Michaelson gives a great simple example. If you are calculating
- 9:36Speaker 2: the cost of a shopping cart. You don't hard code
- 9:39Speaker 2: nine items times ten cents.
- 9:40Speaker 1: You introduce names like quantity in price, right.
- 9:44Speaker 2: You abstract the specific operation into a general, pure rule.
- 9:49Speaker 1: Here's where it gets really interesting, though. Functional programming takes
- 9:53Speaker 1: this a step further. It doesn't just abstract data, it
- 9:56Speaker 1: abstracts the operations themselves.
- 9:58Speaker 2: Yes, functions are tree as first class citizens.
- 10:02Speaker 1: Which sounds fancy, but what does it actually mean.
- 10:04Speaker 2: In practice, it means functions are treated exactly like data.
- 10:07Speaker 2: You can pass a function into another function as.
- 10:10Speaker 1: An argument, like passing a number.
- 10:12Speaker 2: Exactly the same. You can even write a function whose
- 10:14Speaker 2: only job is to dynamically construct and spit out an
- 10:18Speaker 2: entirely new function based on the input it received.
- 10:21Speaker 1: That is wild. You are manipulating logic the exact same
- 10:24Speaker 1: way you manipulate integers.
- 10:26Speaker 2: It is a total paradigm shift.
- 10:28Speaker 1: And the ultimate expression of that is Lisp right list processing.
- 10:31Speaker 1: I know it's one of the earliest languages to adopt
- 10:34Speaker 1: these concepts.
- 10:34Speaker 2: Oh LSP is legendary for this because.
- 10:37Speaker 1: In LASP, the syntax you write to create the program
- 10:41Speaker 1: is literally just a nested list itself.
- 10:43Speaker 2: Right, So the command add two three is mathematically the
- 10:46Speaker 2: same fundamental data structure as a list of groceries like
- 10:50Speaker 2: Apple's milk bread.
- 10:52Speaker 1: The code is data and the data is code. I
- 10:54Speaker 1: think the technical term is homo econicity.
- 10:57Speaker 2: Homo econicity. Yes, it's a bit of a mouthful, but
- 10:59Speaker 2: it basically it means an Lisp program can effortlessly read, rewrite,
- 11:03Speaker 2: and generate other Lisp programs.
- 11:06Speaker 1: On the fly, mind bending.
- 11:07Speaker 2: It creates this incredible fluidity. Imperative languages which strictly separate
- 11:12Speaker 2: the compiled instructions from the memory heap, they simply cannot
- 11:15Speaker 2: mimic that.
- 11:16Speaker 1: But you know what makes this so compelling isn't just
- 11:18Speaker 1: the architecture itself. It's the origin story.
- 11:20Speaker 2: Oh, the history is fascinating.
- 11:22Speaker 1: Right, because this entirely alien way of structuring computation was
- 11:25Speaker 1: not invented by some modern computer scientists trying to optimize
- 11:29Speaker 1: cloud networkloads.
- 11:30Speaker 2: Not at all. It's way older than that.
- 11:32Speaker 1: It was born from a profound philosophical crisis among mathematicians
- 11:36Speaker 1: in the nineteen thirties.
- 11:37Speaker 2: We really have to rewind the tape to understand this.
- 11:40Speaker 2: Long before silicon ships even existed, mathematicians were obsessed with
- 11:44Speaker 2: a seemingly.
- 11:45Speaker 1: Simple question, is math unbreakable?
- 11:48Speaker 2: Exactly? Is it perfect? So in the nineteen twenties, the
- 11:51Speaker 2: German mathematician David Hilbert proposed what became known as Hilbert's program.
- 11:56Speaker 1: Okay, what was his goal?
- 11:57Speaker 2: He wanted to formally prove that mathematics was both consistent
- 12:01Speaker 2: and complete.
- 12:02Speaker 1: Those words probably have very strict definitions in this context.
- 12:05Speaker 2: Very strict consistent means you can never use the rules
- 12:09Speaker 2: of math to prove a contradiction like you can't logically
- 12:12Speaker 2: prove that one equals two.
- 12:14Speaker 1: That makes sense and complete.
- 12:16Speaker 2: Complete means that every single true mathematical statement has a
- 12:19Speaker 2: definitive proof that can be derived from the foundational axioms.
- 12:22Speaker 1: So no mysteries, everything can be proven right.
- 12:25Speaker 2: Hilbert wanted to build a perfect mechanized system of logic
- 12:28Speaker 2: where literally any problem could eventually be solved just by
- 12:32Speaker 2: turning the crank of mathematical rules.
- 12:34Speaker 1: A beautiful dream, and then Kirk Godel totally shattered that
- 12:38Speaker 1: dream in nineteen thirty one.
- 12:40Speaker 2: He utterly obliterated it with his incompleteness theorems how did
- 12:45Speaker 2: you do it? Godel realized that if a formal system
- 12:47Speaker 2: is complex enough to handle basic arithmetic, it can actually
- 12:51Speaker 2: be made to talk about itself.
- 12:52Speaker 1: Okay, this is getting a bit meta.
- 12:54Speaker 2: It is. He developed this brilliant technique called Godal numbering,
- 12:58Speaker 2: where he assigned a unie nique numerical code to every
- 13:01Speaker 2: mathematical symbol and operation.
- 13:04Speaker 1: So he basically turned mathematical equations into a kind of
- 13:07Speaker 1: programming language that could output statements about its own code.
- 13:11Speaker 2: Yes, and using that he encoded a mathematical statement that
- 13:14Speaker 2: translated essentially to this statement cannot be proven.
- 13:17Speaker 1: Oh wow. It's a classic liar's.
- 13:19Speaker 2: Paradox, but weaponized against arithmetic itself. Think about it. If
- 13:24Speaker 2: the statement is false, it means it can be proven,
- 13:26Speaker 2: which means math just proved a falsehood, making the entire
- 13:29Speaker 2: field of mathematics inconsistent.
- 13:31Speaker 1: And if the statement is true.
- 13:33Speaker 2: If the statement is true, it means there is a
- 13:35Speaker 2: true mathematical fact that lacks a proof, meaning mathematics is
- 13:39Speaker 2: fundamentally incomplete.
- 13:41Speaker 1: Wow. So there are true things we can never mathematically
- 13:44Speaker 1: prove exactly.
- 13:45Speaker 2: It's a devastating realization for mathematicians.
- 13:47Speaker 1: I can imagine. Yeah, but the ashes of Hilbert's program
- 13:51Speaker 1: triggered this incredible race, didn't.
- 13:53Speaker 2: It It did. If math has limits, mathematicians urgently needed
- 13:58Speaker 2: to define exactly what could be computed, Like what are.
- 14:01Speaker 1: The strict boundaries of mechanical calculation?
- 14:04Speaker 2: Right? And in nineteen thirty six, two brilliant thinkers published
- 14:08Speaker 2: two completely different road maps for computability.
- 14:11Speaker 1: This is where the timeline of human technology literally splits.
- 14:15Speaker 2: It really does. On one side, you have Alan Turing.
- 14:18Speaker 2: Turing defined computability using a theoretical.
- 14:21Speaker 1: Machine, the famous Turing machine.
- 14:23Speaker 2: Right picture an infinite tape divided into squares with a
- 14:26Speaker 2: read right head, moving left and right, erasing and rewriting
- 14:29Speaker 2: symbols one step at a time based on a set
- 14:32Speaker 2: of rules.
- 14:32Speaker 1: And that tape inherently implies sequence. It moves forward, it
- 14:36Speaker 1: moves backward, It updates the state of the squares during
- 14:38Speaker 1: basically formalized the imperative model we talked about earlier. Do
- 14:42Speaker 1: this change that?
- 14:43Speaker 2: Move here exactly. And on the other side of this
- 14:45Speaker 2: you have Alonzo Church, who is actually Turing's doctoral advisor.
- 14:48Speaker 1: Oh really, I didn't know that.
- 14:50Speaker 2: Yeah, and Church didn't care about tapes or machines or sequence.
- 14:53Speaker 2: He created lambda calculus.
- 14:55Speaker 1: Which is the foundation of functional programming.
- 14:58Speaker 2: Yes, it is a formal system based entirely on stateless function,
- 15:02Speaker 2: abstraction and variable substitution. No tape, no time, no mutation, just.
- 15:07Speaker 1: Pure expressions evaluating other expressions.
- 15:09Speaker 2: If we connect this to the bigger picture, the ultimate
- 15:12Speaker 2: plot twist here is Church's thesis. Turing and Church actually
- 15:16Speaker 2: prove that their completely divergent systems were mathematically equivalent.
- 15:20Speaker 1: Wait, really, the tape and the stateless equations are the same.
- 15:23Speaker 2: Yes, anything you can compute on Turing's sequential tape, you
- 15:27Speaker 2: can compute using Church's timeless lambda equations. They defined the
- 15:32Speaker 2: exact same universe of computability. They were just speaking two
- 15:35Speaker 2: completely different dialects.
- 15:37Speaker 1: But those dialects had massive real world implications.
- 15:40Speaker 2: Huge implications Turing's model maps beautifully onto physical.
- 15:45Speaker 1: Reality because a read write head moving along a tape
- 15:47Speaker 1: is conceptually identical to an electrical switch turning on and
- 15:51Speaker 1: off to update a memory register exactly.
- 15:53Speaker 2: So when engineers built the first digital computers, they basically
- 15:58Speaker 2: built physical Turing machines, and.
- 16:00Speaker 1: So imperative programming languages like Fortran and c were designed
- 16:04Speaker 1: to orchestrate those physical state changes.
- 16:07Speaker 2: While Church's lambda calculus, despite being mathematically pure and beautiful,
- 16:11Speaker 2: was just too abstract for early hardware. It got relegated
- 16:14Speaker 2: to academia.
- 16:15Speaker 1: Well until the nineteen eighties.
- 16:16Speaker 2: Anyway, Right the eighties changed things.
- 16:18Speaker 1: Michaelson's twenty eleven preface spends a lot of time dissecting
- 16:23Speaker 1: this massive resurgence of functional programming during that era.
- 16:27Speaker 2: What happened the tech industry hit a wall. It was
- 16:30Speaker 2: widely known as the software crisis.
- 16:32Speaker 1: Because of the side effects. We talked about.
- 16:33Speaker 2: Exactly, because imperative programs rely on mutating shared state. As
- 16:38Speaker 2: programs grew larger and larger, the side effects became impossible
- 16:41Speaker 2: for humans to manage.
- 16:42Speaker 1: I'm guessing bugs were just multiplying exponentially. Code was crashing
- 16:46Speaker 1: left and right.
- 16:47Speaker 2: There was a genuine panic in the industry. The Japanese
- 16:50Speaker 2: government actually launched the Fifth Generation Computing Initiative, aiming to
- 16:54Speaker 2: build machines that ran entirely on pure.
- 16:57Speaker 1: Logic, and the UK responded to that right they did.
- 17:00Speaker 2: The ALVI program. They heavily funded functional languages like Hope,
- 17:04Speaker 2: mL and eventually Haskell.
- 17:07Speaker 1: Because a pitch was incredibly alluring. Just abandoned imperative state,
- 17:11Speaker 1: adopt Church's timeless mathematics, and your code will be theoretically
- 17:16Speaker 1: bug free and mathematically provable.
- 17:18Speaker 2: It was touted as a total silver bullet.
- 17:20Speaker 1: So what does this all mean? If it was mathematically superior,
- 17:24Speaker 1: why did it fail to take over the industry, Why
- 17:27Speaker 1: did messy imperative languages like C plus plus and Java
- 17:31Speaker 1: end up winning the war?
- 17:32Speaker 2: Well, Michael Sola is refreshingly honest about this in his preface.
- 17:36Speaker 2: Pure declarative and functional languages were basically overhyped because they
- 17:40Speaker 2: ignored the fundamental nature of reality, meaning what exactly, meaning
- 17:43Speaker 2: the physical world is inherently stateful. Time exists, oh or right,
- 17:47Speaker 2: when a human interacts with a computer, clicking a button,
- 17:50Speaker 2: typing a word, saving a file to a hard drive,
- 17:53Speaker 2: those are sequential events. They literally mutate the state of
- 17:56Speaker 2: the world.
- 17:56Speaker 1: Ah. If pure functional programming doesn't allow side of it
- 18:00Speaker 1: effects or state changes, how do you even update a
- 18:03Speaker 1: database or draw a pixel on a screen?
- 18:05Speaker 2: You see the problem. It becomes incredibly cumbersome. You have
- 18:09Speaker 2: to invent these hugely complex mathematical workarounds, things called monads,
- 18:15Speaker 2: just to allow a pure function to interact with the messy,
- 18:19Speaker 2: time bound reality of a user interface.
- 18:21Speaker 1: So pure functional programming is brilliant beyond time, but it
- 18:26Speaker 1: is deeply awkward when forced to operate within time.
- 18:30Speaker 2: That's a great summary. Therefore, imperative languages maintain their dominance
- 18:34Speaker 2: for writing operating systems, desktop applications, and user interfaces.
- 18:40Speaker 1: But the narrative doesn't just end in the eighties, obviously,
- 18:42Speaker 1: since we're still talking about it today.
- 18:43Speaker 2: No, it doesn't, because the Internet changed the scale of
- 18:46Speaker 2: software completely.
- 18:47Speaker 1: Right. We move from desktop apps running on a single
- 18:49Speaker 1: CPU to these distributed cloud systems running across ten thousand nodes, and.
- 18:54Speaker 2: Suddenly we hit the limits of Turing's tape all over.
- 18:57Speaker 1: Again, because when you have a million users hitting at
- 18:59Speaker 1: database simultaneously, imperative state mutation becomes your biggest bottleneck.
- 19:04Speaker 2: Exactly, you spend all your processing power just trying to
- 19:07Speaker 2: lock variables so that all those different threads don't overwrite
- 19:10Speaker 2: each other, like try and keep.
- 19:12Speaker 1: A million people from erasing that jockboard at the same time.
- 19:14Speaker 2: Yes, and to solve this, the industry quietly surrendered to
- 19:19Speaker 2: Alonzo Church.
- 19:20Speaker 1: Which is amazing. We see it everywhere now. Telcom giants
- 19:23Speaker 1: use erlang, which is a deeply functional language to manage
- 19:27Speaker 1: millions of concurrent phone calls without crashing.
- 19:30Speaker 2: Yep. Microsoft baked f sharb into their entire enterprise framework.
- 19:35Speaker 1: And even the biggest imperative heavyweights like Python, c Sharp, Java,
- 19:39Speaker 1: they have aggressively adopted functional features over the years.
- 19:42Speaker 2: They absolutely had to. They absorbed lambda expressions, higher order functions,
- 19:47Speaker 2: and map produce paradigms specifically to handle parallel processing safely.
- 19:51Speaker 1: So it's really a hybrid reality now very much so.
- 19:54Speaker 2: We use Turing's sequential state mutating logic for the boundaries
- 19:59Speaker 2: of our applications, you know the UI, the direct database
- 20:02Speaker 2: rights the things humans physically touched.
- 20:05Speaker 1: But for the massive concurrent data crunching core, we rely
- 20:08Speaker 1: on Church's stateless pure functions.
- 20:10Speaker 2: It's the best of both worlds.
- 20:11Speaker 1: Well, we've covered a staggering amount of theory today. We
- 20:14Speaker 1: really have We impact how the simple act of forbidding
- 20:17Speaker 1: a variable to change, basically banning the eraser on the chalkboard,
- 20:22Speaker 1: completely eliminates side effects.
- 20:24Speaker 2: And we examine how the Church Rosser theorem proves that
- 20:27Speaker 2: pure functions don't care about execution order at all, which
- 20:31Speaker 2: opened the door for massive parallel computing.
- 20:34Speaker 1: We trace those origins all the way back to the
- 20:36Speaker 1: shattering of Hilbert's program by Kurt Guttle, which led to
- 20:39Speaker 1: the defining computability race between Turing's physical tape and Church's
- 20:44Speaker 1: mathematical lamb to calculus.
- 20:46Speaker 2: And then we looked at how the nineteen eighties failed
- 20:48Speaker 2: to force a purely stateless model onto a very stateful world,
- 20:53Speaker 2: leading to today's pragmatic hybrid architecture that we use every day.
- 20:57Speaker 1: It really leaves a fascinating philosophical.
- 20:59Speaker 2: Questions on the table I know where you're going with this.
- 21:02Speaker 1: Right, Because we default to imperative coding because it mirrors
- 21:05Speaker 1: our day to day sequential experience of time. We do this,
- 21:08Speaker 1: then we do that.
- 21:09Speaker 2: It feels natural to us.
- 21:11Speaker 1: But if lambda calculus is actually a cleaner, more mathematically
- 21:14Speaker 1: pure way to process complex logic across a massive network,
- 21:19Speaker 1: how does our own neural network operate?
- 21:21Speaker 2: This raises an important question. Are our brains imperative machines
- 21:25Speaker 2: constantly overwriting localized memory states as we experience time step
- 21:30Speaker 2: by step?
- 21:30Speaker 1: Or is human cognition actually a functional web evaluating infinitely
- 21:34Speaker 1: nested concepts in parallel, completely independent a sequence. Have a
- 21:37Speaker 1: great time mulling that over