To those who maintain a blog and wonder if you’re putting in too much effort relative to the value you get out of it: (1) Let’s chat (2) The person who finds this blog most helpful is myself.
It’s the start of Week 3, thankfully feeling a bit more centered. I had been wondering if I was learning Haskell for the wrong reasons, did a presentation last Friday, and felt reassured in my decision when I was able to draw line linking learning SICP in December to learning Haskell now.
In yesterday’s post, I reflected on doing things for the wrong reason. I suppose it’s common to do things in extremes, hence the stereotype of the investment banker ditching the high life to get into spirituality. My version of this is getting into functional programming after spending time working on infra (though to be fair, I didn’t do it for that long).
I imagine I’m also not alone in wanting to learn one thing and then discover whole new worlds. The starting point was SICP into Haskell. Then there was lambda calculus, type theory, category theory. Maybe proofs. Maybe other functional languages. Maybe implementation / compilers.
In a nutshell, way too much. Too much for a half batch, too much for a full batch. I’m not sure my significant other would love the idea of a year-long sabbatical.
What is it all for anyway? How does it make me a better programmer?
I’m one third into the half batch. I feel compelled to share ’the story so far’.
The question ‘what is functional programming?’ came up in FP study group last week. I like to think of the broader answer around 'functions as first-citizens', namely that you can pass functions as arguments and functions can return other functions (often referred to as closures). This way lots of other imperative languages like Python say can be written in a functional way.
Then there’s functional in the sense of ‘functional vs imperative’. In this context, functions are pure (no side effects) and variables are immutable. Thus calling the same function with the same arguments results in the same output every time.
Now I imagine lots of people wanting to get into functional programming pick up Haskell, but Haskell is additionally a lazy language. This means that evaluation is delayed until results are actually needed, whereas most functional languages are eager. As per Brent Yorgey, It’s impractical and unexpected for a lazy language to not be pure.
We next get to the question of types. Why the tight coupling between functional languages and types? I don’t have a good answer.
Some suggest it’s a practical consideration, but I’m less convinced given the examples of most lisps (functional but dynamically typed) and Rust (imperative but has algebraic data types). I lean more towards the explanation of the language designers being ‘people who like abstract ideas and want to implement abstract ideas’; there’s a tradition of the languages being academic or experimental before becoming ‘industrial strength’. Examples include ML becoming OCaml, and Haskell itself.
I got to the chapter on functors in UPenn's CIS 194, and thought they looked familiar. I had a little digression into Bartosz Milewski’s category theory videos (highly recommend the intro, his enthusiasm is infectious). Functors appeared to me as ’this abstract idea is cool, let’s see what it looks like implemented in the language’.
OK so now we’re in real deep. The intro video talked about the Curry-Howard correspondence, which basically says there is a direct relationship between computer programs (namely the typed lambda calculus) and mathematical proofs. This was extended to the Curry-Howard-Lambek correspondence, that extended the equivalence (or isomorphism) to categories as well.
"Stop, stop, I’m lost!”, you say. I hear you, so am I.
Where do I go from here? I plan to finish up Haskell via CIS 194 (surely you can’t skip monads). I just got a copy of The Little Typer, maybe get Types and Programming Languages in post-batch (Stanford's CS 242 looks pretty cool, even has a paper on the teaching philosophy). RC has Impossible Projects Day on Thursday, here’s my excuse to jump head-long first and see where the tides take me.