148 points · by ColinWright · 4y ago · 75 comments
Yup! Haskell borrows heavily from category theory, and there's a lot of value in knowing the stuff, but people have also been productive in SQL for decades without any formal knowledge of relational algebra.
Asking as a practioner interested in learning the conceptual underpinnings :)
I'd say CT is FP. FP is about doing algebra to derive programs and CT is the math that describes that. In Manfred von Thun’s article "Joy compared with other functional languages" ( https://www.kevinalbrecht.com/code/joy-mirror/j08cnt.html ) he asks,
> Could the language of categories be used for writing programs? Any lambda expression can be translated into a categorical expression, so the language of categories is expressively complete. But this does not make it a suitable language for writing programs. As it stands it is a very low-level language.
I think this book could be seen as the (affirmative) answer to that question.
Which programmer? Bare Lambda Calculus? Wouldn't that be pretty useless?
> Not so with CT. You need to add a lot of structure to get anything close to Lambda Calculus.
I'm not sure I follow, I've heard that "the simply typed lambda-calculus is modeled by any cartesian closed category (CCC)." http://conal.net/papers/compiling-to-categories/
I don’t think I can agree. Clojure is a functional programming language, but is far from doing any algebra.
[1] https://amturing.acm.org/award_winners/backus_0703524.cfm then click on "ACM Turing Award Lecture" or just -> https://dl.acm.org/ft_gateway.cfm?id=1283933&type=pdf
1. Martin Odersky's "Functional Programming Principles in Scala" MOOC on Coursera. Do not focus on the Scala part (5-10% of the course is about Scala).
2. The Little Schemer book. Among the best programming books U have ever read in my life. It actually teaches you how to think recursively. It actually does that.
3. Graham Hutton's Haskell book and YouTube playlist.
I find the ubiquitous idea is that "category theory" is more prestigous than "set theory", and some programmers, instead of seriously learning mathematics, think that learning category theory would fill up their lack of knowledge (in mathematics). It's quite contrary since category theory alone (i.e. without context) is trivial.
Let's be honest: read this book and the series of the author, and try to use the acquired knowledge to prove some (even simple) mathematical theorems.
High applauds for this part.
Category Theory, by design, attempts to be more general, more basic and more abstract.
1. You cannot learn the more abstract stuff first. You have to learn the special cases first- i.e. Calculus, Set Theory, Analysis, etc. You do not start studying Physics with General Relaitivity or Quantum Mechanics because they are more general. You learn them after long years of studuying special Physics of fluid motion, Newton's Law. One should not think that one can simply get a "shortcut" to the most general thing there is, without learning the special cases.
2. A lot of more general sciences are indeed special cases. When you are asked to find the set of points in a certain domain where the derivative of a function cannot be found, you are not actually doing Set Theory. You are doing Calculus.
I believe that the notion one can learn the abstract cases just by studying the abstract science is laughably wrong. They better study Theology. Shouting out "Monad is a monoid in a category of endofunctors" doesn’t teach you Math.
However, let me end this comment and rant with a book suggestion.
Please read "Seven Sketches of Composionality" if are looking for books to learn Category Theory.
He’s objective has never been for the reader to learn this and apply it to prove math theorems.
Both set and category theory are foundational systems for mathematics (or attempting to be). Category theory being newer is trending and probably why you get the sense that it’s considered more prestigious. But I’ve never heard anyone claim it is more prestigious.
I actually criticise the illusion (that the book and the series bring) that the category theory is "the ultimate source" of motivation in FP languages.
On one hand, it's direct (and very natural) to reproduce some categorical structures in a FP language (e.g. Haskell, ML) since such a language is around functions and values. I doubt that such categorical structures should be considered patterns.
On other hand, Haskell or ML does not come from the category theory, it comes from PCF as a language which is created to make program correctness proving is "easy".
I dont want to mean someone using this book to prove mathematical theorems, I just want to say that it's superficial (about both category theory and computer science), and does not bring sufficient knowledge upon that we can build nontrivial results.
A number is ultimately founded on sets. A number is a most basic way to structure sets. Every number can be made out of pure sets (and later on, from tuples of sets-as-numbers)
At the moment, functions are also founded in terms of sets. But I think that mathematics can be constructed based on functions instead of sets. As far as I understand, this can be done using simple type theory; but I still have some studying to do about STT.
In any case, my point is that most mathematics since around the 18th century are not really working with numbers, but with functions as if they were numbers.
(why not both?)
moreover, in terms of sets functions are a relation with some restrictions:
- That they are binary relations
- The "functional-requirement" (as I call it) refers to the difference between a relation and a function. for every x, f(x) = (only one thing); e.g. a relation can have pairs (x,a) and (x,b) but no function can do this.
As far as I've understood, this gets really "fun" when characteristic-functions enter the scene... With these boolean-valued functions it's possible to define a set.
Will use this to test, and learn again about it. Get it while is still hot (Last updated: May 21, 2022)
My day job is programming in Java, and I use streams and lambdas everywhere. I use very little of OO concepts like inheritance. I try to make my data immutable and write functions and methods without side effects, wherever possible.
Popular recent languages like Go, Rust, and Swift borrow a lot from functional programming paradigms.
I'm curious where you are seeing OOP still going strong.
It feels like we're just left with a heavyweight syntax for structs + functions bound to data, which feels like pretty thin gruel.
That seems a little early. I think the 90's were still pretty inheritance-centric.
Java only came out in 1996. UML 2.0 was releaeased in 2005.
I'd say the composition over inheritance movement wasn't widespread until the 2000's,
The concept of composition has long been the bread and butter of functional programming paradigm since antiquity. OOP just adopted it later in the wake of nightmare inheritance hierarchies.
huh?!
golang doesn't. It's quite the antithesis really. They embrace mutability, no null safety, and only recently got generics.
Nowadays I can find a few isolated uses for "classes", but never, and I mean not a single situation where "OOP" (object ORIENTED programming) could ever be preferrable to just using data and functions, whether that's strictly functional programming or plain old procedural.
Could you share more about where you believe OOP hierarchies offer an advantage?
I personally have used a lot of UI libraries, and I would never willingly use anything object oriented again even before React clearly became "the thing". So this is a fairly suprising claim to me in 2022, not so much if it had occurred 10 years ago.
>> much more widely used and honestly now in hindsight probably better tool in most cases.
Knowing only OOP means OOP becomes the only tool for all cases.
``Is Daoism the same as Taoism? Traditionally, yes. The difference in spelling is a problem of transliteration from Chinese to English, where the Chinese pronunciation is somewhere between “Tao” and “Dao.” While it’s far more common to transliterate it as “Taoism,” it is actually pronounced closer to “Daoism.” "[1]
https://bartoszmilewski.com/2014/10/28/category-theory-for-p...
> Master Yoneda says: “At the arrows look!”