Latest / CyberSecurity Summary / Haskell Programming: from First Principles
Transcript
- 0:00Speaker 1: So if I told you to design a tool for
- 0:03Speaker 1: a sailor in the seventeen hundreds to prevent a deadly disease,
- 0:08Speaker 1: you'd probably give.
- 0:09Speaker 2: Them a lemon, right, a literal lemon, exactly.
- 0:12Speaker 1: But if I told you to design a tool to
- 0:14Speaker 1: prevent a modern software engineer from completely losing their mind,
- 0:18Speaker 1: you'd give them, well, Haskell.
- 0:20Speaker 2: Which sounds completely absurd on its face.
- 0:23Speaker 1: I know, it really does. I mean, when you hear
- 0:26Speaker 1: the phrase functional programming or you know Haskell, there is
- 0:30Speaker 1: this immediate reflex to just tense up.
- 0:33Speaker 2: Oh totally.
- 0:33Speaker 1: It has this towering reputation, Yeah, like it's the mount
- 0:36Speaker 1: Everest of coding, this hyper academic, mystical language built by
- 0:40Speaker 1: and for math geniuses.
- 0:42Speaker 2: Well what if that reputation is completely backwards?
- 0:44Speaker 1: Right? What is a language supposedly built for these towering
- 0:47Speaker 1: intellects is actually designed like perfectly for our flawed, limited
- 0:52Speaker 1: human brains.
- 0:52Speaker 2: That's exactly what we're looking at today.
- 0:54Speaker 1: Welcome to today's deep dive. Our mission here is to unpack
- 0:57Speaker 1: this notoriously intimidating subject and show you exactly how it's
- 1:01Speaker 1: built to save you from information overload.
- 1:04Speaker 2: And we are pulling from a truly unique source to
- 1:07Speaker 2: do that. We're diving into excerpts from the book Haskell
- 1:11Speaker 2: Programming from First Principles by Christopher Allen and Julie Marnuki.
- 1:15Speaker 1: Which I have to say has gotten some extraordinary praise.
- 1:19Speaker 2: Oh, unbelievable praise. You have reader feedback from people like
- 1:22Speaker 2: Jason Kurt saying you know, there will forever be a
- 1:25Speaker 2: Haskell before and Haskell after.
- 1:27Speaker 1: That's quite the endorsement.
- 1:28Speaker 2: Yeah, And you even have physicist David Deutsch praising it.
- 1:31Speaker 2: He noted that it acts like a really good teacher
- 1:33Speaker 2: who never presume is what you already.
- 1:35Speaker 1: Know, right, so the right information just surfaces precisely when
- 1:39Speaker 1: you need it exactly. And that is the exact tone
- 1:42Speaker 1: we are bringing to you today. You do not need
- 1:44Speaker 1: a computer science degree or a math background to follow along.
- 1:47Speaker 2: With this, not at all.
- 1:49Speaker 1: We are just exploring how complex ideas can be broken
- 1:53Speaker 1: down to protect your cognitive load. And honestly, the story
- 1:57Speaker 1: of how this book even came into existence sets that
- 2:00Speaker 1: up perfectly.
- 2:01Speaker 2: It really does, because it wasn't written by you know,
- 2:03Speaker 2: two Iver Tower professors coding in a basement since the
- 2:06Speaker 2: nineteen seventies.
- 2:07Speaker 1: Right. The authorship dynamic is pretty fascinating.
- 2:09Speaker 2: It explains the accessibility of the entire text. Really so.
- 2:13Speaker 2: Chris Allen was a veteran programmer of like fifteen years.
- 2:17Speaker 1: He knew what he was doing.
- 2:18Speaker 2: Oh yeah, he had worked extensively in languages like Closure
- 2:21Speaker 2: and Python, but he found himself hitting a wall trying
- 2:24Speaker 2: to teach Haskell to beginners.
- 2:26Speaker 1: Which is where Julie comes in exactly.
- 2:28Speaker 2: His co author, Julie Moronuki was a linguist and when
- 2:32Speaker 2: they began this project, she had absolutely zero programming experience wait,
- 2:37Speaker 2: literally none, literally none. She had to learn what a
- 2:39Speaker 2: compiler was, what a side effect was, what a stack
- 2:43Speaker 2: overflow meant, entirely from scratch.
- 2:46Speaker 1: That is wild, but I guess they teamed up because
- 2:49Speaker 1: existing learning materials for Haskell relied almost entirely on analogies
- 2:54Speaker 1: to other programming.
- 2:55Speaker 2: Languages, right, which is a huge barrier. If a tutorial says, oh,
- 2:58Speaker 2: this is just like a Python dictionary and you don't know.
- 3:00Speaker 1: Python, you're just locked out of the garden.
- 3:02Speaker 2: Exactly. So Julie became the ultimate stress tester for the book.
- 3:06Speaker 1: That makes so much sense.
- 3:08Speaker 2: If a concept relied on a faulty analogy or assumed
- 3:11Speaker 2: prior programming knowledge, she flagged it, and they just rebuilt
- 3:15Speaker 2: the explanation from the ground up.
- 3:17Speaker 1: Okay, but I want to play Devil's advocate here for
- 3:19Speaker 1: a second.
- 3:19Speaker 2: Go for it.
- 3:20Speaker 1: If this language is so brilliant and this book proves
- 3:22Speaker 1: it can be made accessible, why does Haskell have this
- 3:26Speaker 1: wild internet rumor that you need a PhD in I
- 3:30Speaker 1: don't know, monodology, Yeah, just to write a simple Hello
- 3:35Speaker 1: World program.
- 3:36Speaker 2: Yeah, that's the big question.
- 3:37Speaker 1: Is it just academic elitism keeping people away?
- 3:40Speaker 2: To understand why the tech industry sometimes shies away from
- 3:43Speaker 2: its best tools, the authors use a really fascinating historical lens.
- 3:47Speaker 2: They actually compare the adoption of programming languages to the
- 3:50Speaker 2: history of scurvy.
- 3:51Speaker 1: Okay, scurvy, the disease that wiped out pirates and sailors.
- 3:55Speaker 2: That's the one between the year's fifteen hundred and eighteen hundred.
- 3:58Speaker 2: Scurvy killed and estimated two two million sailors.
- 4:01Speaker 1: Oh wow, two millions.
- 4:03Speaker 2: Yeah, it was devastating. But the cure citrus was actually
- 4:05Speaker 2: recommended by the Surgeon General of the East India Company
- 4:08Speaker 2: as early as sixteen fourteen.
- 4:10Speaker 1: It's sixteen fourteen, so they know about it way early.
- 4:12Speaker 1: They did.
- 4:13Speaker 2: It worked beautifully. It saved lives. Men stopped losing their
- 4:18Speaker 2: teeth and dying at sea.
- 4:19Speaker 1: Okay, so if it cured the disease and saved the fleets,
- 4:22Speaker 1: why would they ever stop using it?
- 4:24Speaker 2: Well, because they didn't understand the underlying chemical mechanism. They
- 4:28Speaker 2: knew eating lemons worked, but they didn't know why. No,
- 4:32Speaker 2: So decades later, the British Navy switched from lemons to limes.
- 4:36Speaker 2: Limes were cheaper and easier to source from their own colonies.
- 4:39Speaker 1: But limes aren't the same.
- 4:40Speaker 2: Right, Limes have a significantly lower vitamin C content than lemons,
- 4:45Speaker 2: So the scurvy came back. Oh no Yeah, people started
- 4:48Speaker 2: dying again and the cure was essentially forgotten until ascorbic
- 4:52Speaker 2: acid vitamin C was formally discovered in the nineteen thirties.
- 4:56Speaker 1: That is incredible. I mean, human progress isn't just a
- 4:58Speaker 1: straight line going up all It can invent something amazing,
- 5:01Speaker 1: totally misunderstand the mechanism of why it works, and then
- 5:05Speaker 1: just abandon it for an inferior tool because it's i
- 5:07Speaker 1: don't know, cheaper or a trend.
- 5:08Speaker 2: Ear and technological progress in computer science suffers from the
- 5:12Speaker 2: exact same amnesia. The authors compare relying on dynamically typed
- 5:17Speaker 2: languages like Python or JavaScript to navigating the oceans without lemons.
- 5:23Speaker 1: Okay, break that down for me.
- 5:24Speaker 2: So, in a dynamically typed language, the system doesn't strictly
- 5:28Speaker 2: enforce what kind of data is flowing through it. Okay,
- 5:30Speaker 2: that forces the programmer to hold all the metadata, all
- 5:33Speaker 2: the rules about what kind of data goes where inside
- 5:36Speaker 2: their own.
- 5:37Speaker 1: Head, and human working memory is remarkably fragile. I mean,
- 5:41Speaker 1: we can only hold on to maybe four to seven
- 5:43Speaker 1: distinct items at any given.
- 5:45Speaker 2: Time, exactly. So if you force a programmer to remember
- 5:48Speaker 2: that variable x is a string of text, and variable
- 5:51Speaker 2: y is and integer.
- 5:52Speaker 1: And variable z is a list of user IDs.
- 5:55Speaker 2: Right, eventually they just drop a ball.
- 5:56Speaker 1: Yeah, you're gonna mess that up.
- 5:57Speaker 2: Chris actually shares a painful anecdote in the text about
- 6:00Speaker 2: this exact limitation. He once spent over two hours trying
- 6:05Speaker 2: to track down a single type error in a dynamically
- 6:07Speaker 2: typed language.
- 6:08Speaker 1: Two hours for one error.
- 6:10Speaker 2: Yeah, and the entire program was only two hundred and
- 6:12Speaker 2: fifty lines long.
- 6:13Speaker 1: Oh wow, that is nothing.
- 6:14Speaker 2: But because the system allowed malformed data to just keep
- 6:17Speaker 2: flowing downward. The error propagated far away from the original problem.
- 6:22Speaker 1: It's like a disease spreading silently through the code exactly. So,
- 6:26Speaker 1: dynamic typing is like navigating without lemons because we rely
- 6:29Speaker 1: on our own limited brains to track the data types.
- 6:33Speaker 1: How does Haskell actually solve that? What is it? Vitamin C?
- 6:36Speaker 2: Haskell uses strict static typing. The compiler, which is the
- 6:40Speaker 2: program that translates your code into machine language. It acts
- 6:44Speaker 2: as an impenetrable wall before the program is even allowed.
- 6:47Speaker 1: To run, so it checks everything.
- 6:48Speaker 2: First, every single piece of data, against strict roles. If
- 6:52Speaker 2: you try to hand a text string to a math function,
- 6:54Speaker 2: the compiler stops you immediately and says this is inconsistent.
- 6:57Speaker 1: It tracks the metadata so your brain doesn't.
- 6:59Speaker 2: Have to You can refactor or change thousands of lines
- 7:02Speaker 2: of code without fear knowing the compilers doing the heavy
- 7:05Speaker 2: lifting of remembering what everything is.
- 7:07Speaker 1: That brings us to a really crucial pivot, because to
- 7:11Speaker 1: build a tool that can flawlessly protect our working memory,
- 7:15Speaker 1: we need a solid mathematical foundation. And the book doesn't
- 7:20Speaker 1: start by having you type code into a terminal. It
- 7:22Speaker 1: actually takes us back to the nineteen thirties.
- 7:25Speaker 2: Right to a mathematician named Alonzo Church.
- 7:28Speaker 1: Yes, and something called the lambda calculus, which I have
- 7:32Speaker 1: to admit. When I was first reading the sources, lambda
- 7:34Speaker 1: calculus sounded absolutely terrifying.
- 7:36Speaker 2: It sounds like advanced calculus, which scares a lot of.
- 7:39Speaker 1: People, definitely, But as I dug into the actual mechanics
- 7:43Speaker 1: of it, I realized it's really just a system of substitutions.
- 7:47Speaker 1: It reminded me exactly of playing mad lips.
- 7:49Speaker 2: Oh, that's a great way to think about it.
- 7:51Speaker 1: You know those fill in the blank puzzle books where
- 7:53Speaker 1: you ask a friend for a noun and then you
- 7:55Speaker 1: write it into a sentence to make a funny story.
- 7:57Speaker 2: That is a remarkably accurate way to visualize the mechanism.
- 8:01Speaker 2: In Lenda calculus, an abstraction, which is what they call
- 8:04Speaker 2: a function, operates just like a mad Libs sentence. Okay,
- 8:08Speaker 2: the function has a head and a body.
- 8:11Speaker 1: So the head of the lambda function is like the
- 8:13Speaker 1: prompt in mad Libs. Right, it's the blank space that
- 8:15Speaker 1: tells you what kind of word you need. It says,
- 8:17Speaker 1: give me a noun.
- 8:19Speaker 2: That's the parameter, right exactly, and then the body of
- 8:23Speaker 2: the function is the actual sentence you were going to
- 8:25Speaker 2: write that noun into. Building on your analogy, A formal
- 8:28Speaker 2: lambda term relies on three components expressions, variables, and those abstractions.
- 8:35Speaker 2: And a foundational rule of this system is that the
- 8:37Speaker 2: label on that blank space doesn't matter at all.
- 8:40Speaker 1: Meaning it doesn't matter if I ask my friend for
- 8:42Speaker 1: no one noun a or just a describing word, right,
- 8:46Speaker 1: as long as they give me a noun, it goes
- 8:48Speaker 1: into the same blank space in the sentence.
- 8:50Speaker 2: The formal mathematical term for that is alpha equivalents. It
- 8:53Speaker 2: dictates that a function written as say, lambda x dot
- 8:56Speaker 2: x is logically identical to a function written as lambda
- 8:59Speaker 2: y dot com.
- 9:00Speaker 1: Why so letters don't matter.
- 9:01Speaker 2: The letters x and R are just placeholders. They hold
- 9:04Speaker 2: no inherent meaning until you actually apply an argument to them.
- 9:07Speaker 1: Okay, so we have our mad lib sentence, We have
- 9:09Speaker 1: our blank space, and ask my friend for a noun
- 9:10Speaker 1: and they say banana.
- 9:12Speaker 2: Classic mad libs.
- 9:13Speaker 1: Always, I take the word banana, I substitute it into
- 9:17Speaker 1: the blank space in the sentence, and I cross out
- 9:19Speaker 1: the prompt. That mechanical process of substituting and crossing out
- 9:23Speaker 1: the prompt, that's what the text calls beta reduction, right.
- 9:27Speaker 2: Yes, exactly. In beta reduction, you apply a function to
- 9:30Speaker 2: an argument. You take the input expression, substitute it for
- 9:34Speaker 2: all instances of the bound variable inside the body of the.
- 9:38Speaker 1: Function, and then cross out the prompt.
- 9:40Speaker 2: Crucially, yes, you eliminate the head. The head's only purpose
- 9:43Speaker 2: was to bind the variable. Once the substitution is complete,
- 9:46Speaker 2: it just vanishes.
- 9:48Speaker 1: This is a massive light bulb moment for me. If
- 9:50Speaker 1: we strip away the intimidating jargon, evaluation is really just simplification.
- 9:55Speaker 2: It really is. The authors provide a very intuitive mathematical
- 9:59Speaker 2: example to prove this. Consider the expression two thousand divided
- 10:03Speaker 2: by one thousand. Okay, that is a mathematically valid expression,
- 10:06Speaker 2: but it is not fully reduced.
- 10:07Speaker 1: Right Because if someone asked me how many apples I had,
- 10:10Speaker 1: I wouldn't say I have two thousand divided by one
- 10:12Speaker 1: thousand apples.
- 10:13Speaker 2: That would be very weird.
- 10:14Speaker 1: My brain has to do extra work to parse that
- 10:16Speaker 1: I have two apples.
- 10:18Speaker 2: Exactly. The number two is the normal form of that expression.
- 10:23Speaker 2: Beta normal form is achieved when you cannot apply any
- 10:27Speaker 2: more lambdas to arguments.
- 10:29Speaker 1: So you're at the end of the line.
- 10:31Speaker 2: Right, There are no more evaluation steps to take. Nothing
- 10:34Speaker 2: is left to simplify the ultimate goal of any program
- 10:37Speaker 2: in this paradigm is to reach its normal form, where
- 10:40Speaker 2: it is completely evaluated.
- 10:42Speaker 1: In tying this back to our overarching theme, simplifying down
- 10:46Speaker 1: to a normal form is another way to save cognitive load.
- 10:49Speaker 2: Oh.
- 10:49Speaker 1: Absolutely, you aren't forcing the programmer or the machine to
- 10:52Speaker 1: juggle unresolved equations. You distill it down to its most
- 10:55Speaker 1: basic truth. But I guess how does this nineteen thirties
- 10:59Speaker 1: math translate into actual software engineering.
- 11:02Speaker 2: Well, it translates through the concept of pure functions. Because
- 11:05Speaker 2: Haskell is built on lamb to calculus, it relies entirely
- 11:08Speaker 2: on these pure mathematical relations. Okay, there is a quote
- 11:11Speaker 2: from Mike Hammond in the text that captures the essence
- 11:13Speaker 2: of this perfectly. He says, functions are beacons of constancy
- 11:17Speaker 2: in a sea of turmoil.
- 11:18Speaker 1: Beacons of constancy. I like that. But what makes a
- 11:21Speaker 1: function pure or constant in a machine?
- 11:23Speaker 2: It comes down to a property called referential transparency. A
- 11:27Speaker 2: pure function is a strict, unbreakable relation between inputs and outputs,
- 11:32Speaker 2: so it's locked in completely. If a function is called
- 11:35Speaker 2: F and you give it the input, one and it
- 11:37Speaker 2: returns the output A. It must return A every single
- 11:41Speaker 2: time it is evaluated, no matter.
- 11:42Speaker 1: What time of the day the computer is running, no
- 11:44Speaker 1: matter what other apps.
- 11:46Speaker 2: Are open, no matter what is happening on the network. Yes,
- 11:48Speaker 2: if a function returns X on Tuesday and then returns
- 11:52Speaker 2: why on Wednesday for the exact same input, it is
- 11:55Speaker 2: an invalid function in functional programming.
- 11:58Speaker 1: But doesn't that happen a lot in other languages.
- 12:00Speaker 2: It happens all the time in dynamically typed languages, because
- 12:04Speaker 2: a function might secretly rely on a global variable that
- 12:07Speaker 2: changed somewhere else in the system.
- 12:09Speaker 1: Ah, I see.
- 12:09Speaker 2: That is called a side effect. Pure functions have no
- 12:12Speaker 2: side effects.
- 12:12Speaker 1: This is exactly how we prevent the working memory overlow.
- 12:15Speaker 1: We talked about what the scurvy analogy. If you know
- 12:18Speaker 1: for an absolute fact that an input always yields the
- 12:21Speaker 1: exact same output, you don't have to keep a mental
- 12:23Speaker 1: list of exceptions. You don't have to wonder, wait, did
- 12:27Speaker 1: this variable change while I wasn't looking right?
- 12:29Speaker 2: You can trust the bricks you're building with That predictability
- 12:32Speaker 2: allows you to build massive, sprawling software systems out of small, reliable,
- 12:37Speaker 2: independent functions.
- 12:38Speaker 1: You just assemble them like interlocking gears.
- 12:40Speaker 2: Exactly knowing they will never spontaneously change shape or turn
- 12:44Speaker 2: in the wrong direction.
- 12:45Speaker 1: Because these pure functions are perfectly predictable because they never
- 12:49Speaker 1: change based on hidden variables, you don't need to boot
- 12:51Speaker 1: up a massive, complex program just to see if one
- 12:55Speaker 1: tiny piece works.
- 12:56Speaker 2: You don't.
- 12:57Speaker 1: You can just ask the machine to evaluate a single
- 12:59Speaker 1: function in isolation, which brings us to how we actually
- 13:02Speaker 1: sit down and talk to this system on a computer screen.
- 13:05Speaker 2: Right getting to the practical side, the sources introduced two
- 13:08Speaker 2: main ways to interact with Haskell. You can write your
- 13:11Speaker 2: code into permanent source files, or you can use a
- 13:14Speaker 2: r EPL.
- 13:15Speaker 1: R EPL read evil print loop.
- 13:17Speaker 2: Exactly in Askel's case. This interactive environment is called GHCI.
- 13:23Speaker 2: It is a prompt where you type in an expression,
- 13:25Speaker 2: hit enter, and the system instantly reads it, evaluates it
- 13:29Speaker 2: to its normal form, and prints the result back to you.
- 13:32Speaker 1: So it's a laboratory for immediate feedback.
- 13:34Speaker 2: That's a great way to put it.
- 13:35Speaker 1: But the way we type things out, the syntax has
- 13:38Speaker 1: some quirky rules that can really trip up a beginner,
- 13:42Speaker 1: particularly how we order the words and symbols.
- 13:44Speaker 2: Yeah, this raises the distinction between prefix and infix functions.
- 13:48Speaker 2: By default, functions in Haskell use prefixed syntax. The function
- 13:53Speaker 2: name comes first before the arguments. So if you have
- 13:56Speaker 2: a function that triples a number, you type the word
- 13:58Speaker 2: triple a space and then the number.
- 14:00Speaker 1: Two, soly issuing a command in English triple this number
- 14:03Speaker 1: two exactly.
- 14:04Speaker 2: But math operators like the plus sign or the multiplication
- 14:08Speaker 2: sign are actually functions too. They take inputs and return
- 14:12Speaker 2: an output. However, they are infix operators, so they sit.
- 14:15Speaker 1: In the middle of their arguments like one plus one.
- 14:17Speaker 2: Right, which makes sense because that's how we all learn
- 14:19Speaker 2: math in elementary school. But the book points out that
- 14:22Speaker 2: mixing these up introduces strict rules about associativity.
- 14:26Speaker 1: Hold on, if you're listening to this while commuting or
- 14:28Speaker 1: making dinner, your eyes might have just glazed over at
- 14:31Speaker 1: the word associativity. Let's ground this fair point. Why does
- 14:34Speaker 1: a programmer actually need to care if the math goes
- 14:36Speaker 1: left to right or right to left.
- 14:38Speaker 2: Because the computer will follow its rules flawlessly, whether you
- 14:41Speaker 2: intended it to or not, which can lead to wildly
- 14:44Speaker 2: different results.
- 14:45Speaker 1: Give me an example.
- 14:46Speaker 2: Okay, if you type two, three four in into the
- 14:49Speaker 2: r epl, the machine sees two exponent operators. Because exponentiation
- 14:54Speaker 2: associates to the right, it calculates the right most part first,
- 14:58Speaker 2: so three four right, which is e eighty one. Then
- 15:00Speaker 2: it calculates to eighty one, which is an astronomically large number.
- 15:04Speaker 1: Wow. But if you assumed it read left to right
- 15:07Speaker 1: like regular English text, you would expect it to calculate
- 15:09Speaker 1: two three first, which is eight right, and then raise
- 15:12Speaker 1: eight to the fourth power, which is only four ninety
- 15:15Speaker 1: six exactly.
- 15:16Speaker 2: So if your software was calculating a financial interest rate
- 15:19Speaker 2: and you misunderstood the associativity, you just bankrupted the company.
- 15:23Speaker 1: Yikes. A perfect example of why I understand the strict
- 15:26Speaker 1: rules of the language prevents catastrophic failure.
- 15:29Speaker 2: Yeah, and the book dives into another concrete mathematical example
- 15:32Speaker 2: that illustrates this beautifully, the modulo clock using the mod
- 15:37Speaker 2: and REM functions.
- 15:38Speaker 1: Both of those deal with division, but mod stands for
- 15:40Speaker 1: modulo and REM stands for a remainder. Walk me through
- 15:44Speaker 1: modular arithmetic using a standard clock.
- 15:46Speaker 2: Sure, look at a standard twelve hour analog clock.
- 15:49Speaker 1: Yeah.
- 15:49Speaker 2: If the current time is eight zero zero and you
- 15:52Speaker 2: need to know what time it will be in eight hours,
- 15:54Speaker 2: you don't add eight plus a and declare it will
- 15:56Speaker 2: be sixteen o'clock.
- 15:57Speaker 1: Obviously not on a twelve hour dial. The numbers wrap
- 16:01Speaker 1: around the modulus, which is twelve, So you add four
- 16:04Speaker 1: hours to reach twelve zero zero. The dial resets to
- 16:07Speaker 1: zero and you add the remaining four hours. So eight
- 16:10Speaker 1: hours after eight zero zero is four point zero.
- 16:13Speaker 2: That is arithmetic modulu twelve. Haskell actually includes two different
- 16:16Speaker 2: functions for this, mod and REM, and they usually the
- 16:19Speaker 2: exact same answer, usually, but they diverge in behavior when
- 16:23Speaker 2: you introduce negative numbers. If one argument is negative, mod
- 16:28Speaker 2: takes the sign of the divisor the number you are
- 16:30Speaker 2: dividing by, okay, but REM takes the sign of the
- 16:32Speaker 2: dividend the number being divided.
- 16:34Speaker 1: Okay. Let's put this in a real world scenario so
- 16:36Speaker 1: we understand why this matters. Let's say you are building
- 16:38Speaker 1: a calendar application.
- 16:40Speaker 2: Okay, a calendar app.
- 16:41Speaker 1: Days of the week loop every seven days, so your
- 16:44Speaker 1: modulus is seven. Tuesday is day two. A user wants
- 16:48Speaker 1: to search for an event that happened ten days ago.
- 16:51Speaker 1: You subtract ten from two, which gives you negative eight.
- 16:54Speaker 2: Right, and if you use the REM function to divide
- 16:57Speaker 2: negative eight by seven, the remainder takes the sign of
- 16:59Speaker 2: the negative of eight. It returns in negative.
- 17:01Speaker 1: One, but there is no negative first day of the week.
- 17:04Speaker 1: The calendar application completely.
- 17:05Speaker 2: Breaks exactly, but if you use the mod function, it
- 17:08Speaker 2: correctly wraps around the negative value and returns a positive six,
- 17:11Speaker 2: which corresponds to Saturday.
- 17:13Speaker 1: Wow.
- 17:14Speaker 2: Knowing that subtle distinction prevents massive bugs when you are
- 17:17Speaker 2: dealing with wrapped values like times, dates, or even graphical
- 17:21Speaker 2: user interfaces.
- 17:22Speaker 1: But thinking about typing all of this outkeeping track of
- 17:26Speaker 1: prefix infix associativity whether a value might be negative, I mean,
- 17:31Speaker 1: it feels like the code could become incredibly dense and
- 17:34Speaker 1: visually overwhelming to read.
- 17:37Speaker 2: It could, which is why programming languages utilize something called
- 17:40Speaker 2: syntactic sugar.
- 17:42Speaker 1: Syntactic sugar beyond sounding delicious, what is the actual mechanism here?
- 17:47Speaker 2: Syntactic sugar is a feature of a programming language's grammar
- 17:50Speaker 2: designed strictly to make things easier for humans to read
- 17:53Speaker 2: and write. Oh nice, Yeah, It does not change the
- 17:56Speaker 2: underlying semantics or the lambda calculus math at all. For example,
- 18:00Speaker 2: simple to make a number negative in Haskell, the formal
- 18:03Speaker 2: mechanism is to apply a function called negate to it,
- 18:06Speaker 2: so you'd.
- 18:07Speaker 1: Have to type the word negate, add a space, and
- 18:09Speaker 1: tack the number nine right.
- 18:10Speaker 2: But seeing the word negate everywhere clutters the screen, So
- 18:13Speaker 2: Haskell allows you to just type negative nine.
- 18:15Speaker 1: Ah. So behind the scenes, the compiler is still translating
- 18:18Speaker 1: that little dash into the formal negate function. Hmm, but
- 18:22Speaker 1: I don't have to look at the clunky word exactly.
- 18:25Speaker 2: Syntactic sugar is a transformation performed by the compiler after
- 18:28Speaker 2: the code is parsed. It allows you to write code
- 18:30Speaker 2: that looks like natural math without sacrificing the strict underlying logic.
- 18:35Speaker 1: And linking this right back to where we started, Syntactic
- 18:37Speaker 1: sugar isn't just about making the code look pretty visual
- 18:41Speaker 1: Clutter takes cognitive energy to parse.
- 18:43Speaker 2: It absolutely does.
- 18:44Speaker 1: By reducing the noise on the screen, the language is
- 18:47Speaker 1: actively protecting your working memory, making it easier for your
- 18:51Speaker 1: limited monkey brain to spot actual logic errors.
- 18:54Speaker 2: Everything in Haskell, from the strict types acting as your
- 18:57Speaker 2: scurvy lemons, to the simplification of lamb to calculus, to
- 19:01Speaker 2: the pure functions and syntactic sugar, is engineered to reduce cognitive.
- 19:05Speaker 1: Load zooming out. The journey we just took you on
- 19:08Speaker 1: covers massive ground. We started with the realization that software
- 19:12Speaker 1: engineering needs strict rules because human memory is deeply flowed,
- 19:16Speaker 1: very flawed. We travel back to the nineteen thirties with
- 19:18Speaker 1: the Lonzo Church to understand that evaluation is simply the
- 19:21Speaker 1: process of reducing a function down to its normal form.
- 19:25Speaker 1: We saw how referential transparency gives us predictable tools that
- 19:29Speaker 1: don't secretly change behavior based on hidden variables.
- 19:32Speaker 2: And we arrived at the practical mechanics of interacting with
- 19:35Speaker 2: the language, understanding that concepts like associativity and modular arithmetic
- 19:40Speaker 2: aren't just academic trivia.
- 19:42Speaker 1: No, they really aren't.
- 19:43Speaker 2: They are the actual mechanisms that keep complex systems from collapsing.
- 19:47Speaker 1: It is a profoundly beautiful system when you realize every
- 19:51Speaker 1: scary sounding mathematical term is just a guardrail design to
- 19:55Speaker 1: keep you safe.
- 19:56Speaker 2: It is, But you know. There is one final concept
- 19:59Speaker 2: from the Lamb to Calculus text that has fascinating implications
- 20:02Speaker 2: far beyond writing code. What it is the concept of divergence.
- 20:07Speaker 2: In lambda calculus, an expression is supposed to converge down
- 20:10Speaker 2: to a normal form. You simplify it until.
- 20:12Speaker 1: The work is done right like the two apples.
- 20:14Speaker 2: Exactly, but sometimes an expression diverges the substitutions loop endlessly
- 20:19Speaker 2: applying functions over and over without ever terminating or reaching
- 20:23Speaker 2: a simplified meaningful answer. Wow, the system just spins in
- 20:27Speaker 2: a loop.
- 20:27Speaker 1: Forever, endless motion, without ever producing a result.
- 20:30Speaker 2: Exactly. So we want to leave you with this thought
- 20:33Speaker 2: to mull over. Based on the source material, look at
- 20:36Speaker 2: your own daily routines, your habits, your information consumption. How
- 20:40Speaker 2: much of your day is spent in divergence looping endlessly
- 20:43Speaker 2: through tasks, scrolling through feeds, spinning your wheels without ever
- 20:47Speaker 2: reaching a simplified, meaningful normal form.
- 20:50Speaker 1: That's a powerful question.
- 20:51Speaker 2: What would it look like to beta reduce Stron life