246 points · by _zhqs · 11y ago · 156 comments
What sold me on applicatives was being able to write "traverse", and similar operations, that would be m * n if you had to write them for each (traversable, applicative) pair but can be m + n instead ( http://m50d.github.io/2013/01/16/generic-contexts.html ). That's a very concrete code saving. Having three examples of things that form categories is great - but can we show a real-world function that we can write that takes a generic category, that does something useful with each of these three examples? That would demonstrate that we're getting real value (i.e. a code saving) out of the abstraction.
For example, take the following example type:
newtype Example f c a b = Example (f (c a b))
instance (Applicative f, Category c) => Category (Example f c) where
id = Example (pure id)
Example f . Example g = Example (liftA2 (.) f g)
You can prove that if `c` satisfies the `Category` laws and `f` satisfies the `Applicative` laws, then `Example f c` also satisfies the `Category` laws.This in turn lets you take any `Category` and keep extending it with as many `Applicative`s as you want in any order, confident in the knowledge that your extended `Category` still satisfies the `Category` laws.
This is a common pattern in code that is organized around category theory and/or abstract algebra and I wrote a post showing a simpler example of this phenomenon (using `Monoid` instead of `Category`): http://www.haskellforall.com/2014/07/equational-reasoning-at...
If you haven't already, you should play around with the pipes library, because it makes very heavy use of categories and it's an extreme positive example of composability.
As another practical example, Haskell's class constraints form a thin category, with constraint entailment as arrows. This means that instance resolution never depends on ordering of imports, local bindings, or basically anything other than the raw set of available instances, and also any two instances at the same type must be equal. This buys us great scalability and refactorability, most notably in comparison to Scala, where alphabetizing module imports sometimes breaks programs.
That said, in category theory one rarely works with vanilla categories but rather other abstractions formulated in categorical language. Similarly, in Haskell vanilla categories aren't as useful as the many well-known categorical abstractions (basically, the core Functor - Applicative - Monad hierarchy is directly category-theory inspired, and they've proven to be insanely useful).
I didn't find that example particularly motivating since I can easily think of a simpler solution: exceptions. (Alternatively, if I was using C, it'd be setjmp()/longjmp(), which perform a very similar style of control flow.)
<T> T doSomething(Callback<T> callback)
<T, E extends Exception> T doSomethingThrow(CallbackThrow<T, E> callback) throws E
and even that doesn't properly cover the cases, because ideally you'd like to be able to pass a callback that throws two or more unrelated exceptions as well. Setjmp/longjmp is "simple" like goto is simple; if you want to refactor a function that uses them you have to think very carefully.If we have \/, the possibly-error is just a value. We can use it with generic functions in the normal way. We can refactor them in the obvious way and it will just work correctly, and the type system can assure us we've done it right.
Are they really? I'd like to see the actual code which gets generated from that ultra-abstract solution, since I already know what creating an exception frame or setjmp/longjmp turns into.
If we have \/, the possibly-error is just a value.
If you use pointers, then an error can also be signified with a value (0), and there's also this very simple but possibly slightly less efficient way (in the success case):
ret = (v1 = func1(v0)) && (v2 = func2(v1)) && ...Category theory was invented for a deeper reason - to have a rigorous definition of a natural transformation, to enable a precise language to translate back and forth between algebra and topology.
Note that this is not a comment about the usefulness of category theory in theory of programming languages, it is about the uselessness of the linked article in talking about it.
As another commenter pointed out, in practice Haskell functions as values don't even form a category. This actually matters as illustrating the practical difficulties involved.
As a mathematician, I'd say most practicing computer scientists have a very skewed/warped understanding of category theory, and in their ignorance of other theoretical concepts, tend to misunderstand what they do think they know about. In general defining what you're trying to solve, tethered to a real, meaty problem, and then judging theoretical formulations for succeeding at these use cases is a good way to not get stuck in 'empty abstractions'. New mathematics gets invented (and judged) as a way of solving problems. The chain of reasoning might be long but it's there. People don't invent new terminology for no reason (and even if they did, and it didn't help for understanding a problem, it'd get no traction)
Did you read my comment? I claim that because something is associative and has identity, concepts clarified and used in the 19th century, is not sufficient motivation to bring about category theory. It's not used for anything in this article.
Correct, it is not category "theory". The terminology "category theory" here is used analogously to how database people say relational algebra is based on "set theory". It sounds a bit silly to mathematical ears.
On the other hand, the article is about much more than composing functions. In fact the section headings are "The function category", "The Kleisli category", and "The Pipe category". The rudimentary structure of a category is useful for putting disparate concepts on common ground.
What the Haskell community keeps running into is that most people don't think in theories. Trying to prove the theory to be practical has a poor success rate. They need to implement useful things that people love, then show how the theory got them there naturally.
Sentences like this:
> Category theory codifies this compositional style into a design pattern, the category.
To the average person, a theory codifying a style into a pattern just isn't useful. What does that do? Monads are a common joke to this effect. They are wonderfully useful but poorly understood by most developers. It isn't being right that matters if few understand you.
Why was Rails successful?
Sure Ruby is nice, but Python is very similar (and it wasn't the `do...end` blocks.)
It's because Rails could be used to easily build functional CRUD apps — Whoops! it works — that made difficult easy. Sandy Metz doesn't get heard if DHH isn't building Basecamp.
As a philosopher, it pains me to know people don't think that way, but if you aren't changing people's lives then all the theory is just mental masturbation.
Real human beings use Haskell every day and love it.
Real human beings are capable of learning about teh scary maths and abstract theories.
You studied philosophy? Are you aware that most people don't understand anything about philosophical theories other than The Secret? Have you thought about how maybe those theories can change people's lives even though they're not aimed at a lowest common denominator? E.g. by being influential in the long run, and also by being intellectually stimulating to people who do bother to learn about it?
Rails-style success is not the goal for Haskell. It is an explicit anti-goal: the motto is "avoid success at all costs."
Terse and rude counterpoint to your thesis: Average people are lazy idiots and designing your language to appeal to them will result in a very popular incoherent mess, like Java and Ruby, and Dijkstra will make pointed remarks at you from his grave.
Although it isn't stated as such, I think the point is that the haskell community is, on the whole, truly awful at pedagogy.
I'm perfectly fine with the notion that Haskell isn't for everyone, but being a poor pedagogue is always a bad thing.
Teaching isn't easy, and the abundance of poor pedagogy is surely a big reason why so many people develop mathematical anxiety.
https://en.wikipedia.org/wiki/Mathematical_anxiety
> Students often develop mathematical anxiety in schools, often as a result of learning from teachers who are themselves anxious about their mathematical abilities in certain areas. Typical examples of areas where mathematics teachers are often incompetent or semi-competent include fractions, (long) division, algebra, geometry "with proofs", calculus, and topology.
The programming world lately is inundated with tutorials that take their pedagogical style from the Teletubbies or at best Bob Ross. Maybe that is not a viable way of teaching Haskell—maybe there will need to be actual study involved, with textbooks and exercises and trained teachers. I don't really know.
https://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD103... ("On the Cruelty of Really Teaching Computer Science")
> So, if I look into my foggy crystal ball at the future of computing science education, I overwhelmingly see the depressing picture of "Business as usual". The universities will continue to lack the courage to teach hard science, they will continue to misguide the students, and each next stage of infantilization of the curriculum will be hailed as educational progress.
But.
If you ever see a technology truly suffer from "poor pedagogy" then it has a secret: in some fundamental, underlying way, it sucks.
Now the rules of the game are different. Suddenly, those who understand it will keep it under their breath and muddy the issue. No one will be explicit about these design choices and simply explain it: to explain it is to criticize it.
Then you have this case where people are holding their tongue, and those who eventually figure something out join that small cabal and simply don't mention it in normal, sane terms. They just don't - it would be rude to do so.
So remember. If you ever perceive poor pedagogy online in any tech subject, then it is camouflage, you are being lied to. In some fundamental way nobody will mention, it simply sucks.
At that point it's up to you to read between the lines and decide whether it still has enough benefits for you to learn it.
This is so funny
Yeah, Ruby and Java are not great. But they get the job done and produce value, and a lot of people use it.
I couldn't care less what Dijkstra thinks, he's not the one paying my bills
If you can see the value in Haskell great. But I find it hard to remember where are the big technology companies using Haskell (or tools built with it). Maybe because if you force 'mathematical consistency' in an inconsistent world everything else sucks
Look up Facebook's use of Haskell if you're curious about industry use.
https://code.facebook.com/posts/302060973291128/open-sourcin...
I worked for a startup that used Haskell for its entire backend, including a custom kind of graph database. I joined my coworkers to a Haskell hackathon in Zürich and met hundreds of people using the language commercially (and happily).
It's not that Java and Ruby suck—it's just that they're incoherent and messy. That may sound like slander but I have used both languages professionally, I have contributed to both Rails and the Ruby interpreter, I don't think they are bad tools. Everything is a tradeoff. If you CAN'T see the value in Haskell, I humbly recommend you look into it, but I can't force you to become interested.
That's a noble idea. Knowing this also makes it easier for me to chose to avoid reading articles about it.
While it's certainly cute that I can `gem install` a CMS, the Ruby ecosystem is infamous for its magical, non-composable, monolithic frameworks. The functional ecosystems are working toward fixing the all-too-familiar problem where you have to either start over, or hack apart some giant stateful mess anytime your exact usecase hasn't already been built as a library. It's easy to throw a nice looking house together with Lincoln Logs, but I'd take Lego instead any day.
Edit: Also, just because someone hasn't built the tallest building in your neighborhood yet doesn't mean they're not building anything. JP Morgan, Kapersky, Facebook, and IMVU are hiring Haskell devs, just off the top of my head.
Worth noting that finance industry heavyweights such as JP Morgan and Standard Chartered (largest Haskell shop in the world) are laying off more than they're hiring these days[0][1], though unlikely this trend would directly affect tech hires (current batch of layoffs seem to be a trimming of management tier).
On a somewhat related note: were Standard Chartered to open source their fork of GHC many Haskellers not sold on lazy-by-default would rejoice; from Scala side of the fence my interest in Haskell would increase 10X were that to happen, line numbered stack traces alone, who woulda "thunk" it ;-)
Moving forward Haskell's probably going to continue to be pilfered of its theoretical gems by other languages that leap frog it in terms of adoption. Not a bad thing if we take SPJ's "avoid success at all costs" at face value.
[0] http://www.bloomberg.com/news/articles/2015-05-28/jpmorgan-s...
[1] http://www.bloomberg.com/news/articles/2015-07-20/standard-c...
But here, we have an article trying to make some concept approachable - some math, not tied to a specific language. Maybe it's hard for most to follow, since it assumes the readers knows what a monad is. That's fair, but it'd be the same if it were Scala.
The top comment here - and a significant number of the upvoted comments here, and on every similar article - are just baseless attacks against the idea that people should learn this. Not questions or technical discussion, just attempts to ostracize the part of the community that finds it valuable. It's anti-intellectualism, plain and simple. Maybe it's the terminology, or the syntax, or because articles didn't show the lock before giving the key, but it is what it is.
- Re: Hiring - JP Morgan may be doing layoffs somewhere, but I mentioned them because they made a "Hiring Haskell Devs" post within the last week.
Edit: Seriously, go re-read that top comment, from the condescending reference down to the assertion that it's all mental masturbation. In response to a post by a knowledgeable person trying to teach something useful to people who are interested. That's the top comment. Embarrassing.
Indeed. Hiring of Haskellers continues apace at SC: https://twitter.com/donsbot/status/654630194519646208
> were Standard Chartered to open source their fork of GHC many Haskellers not sold on lazy-by-default would rejoice
It's not a fork of GHC. It's an entirely new compiler, called Mu.
I don't think general layoffs at all correlate to language usage in this case (they didn't cut a Haskell team, specifically).
[1] https://www.reddit.com/r/haskell/comments/3re0kp/jpmorgan_ha...
People don't understand what monads are because they don't know what problem they solve.
This article has the same problem. It doesn't explain what problem categories solve. Well it does but the average reader doesn't understand the problem exists.
If Haskell's "Monad" type class were instead called "AbstractComputationFactory" or some other such intimidating technobabble, then when someone looks up what is the superclass of IO they might just think "oh, that's some weird detail, whatever, I might learn about that later." Since instead the name "Monad" is vaguely funny and appealing, people want to master that concept in principle before they even get "Hello, world!" to run in GHCi.
Of course people are free to focus on whatever they want, and we can talk about the possibility of improving the pedagogical aspects of Haskell, and probably university teachers have interesting things to say about that.
But there is no magic way to explain an algebraic concept that will suddenly make it intuitive and easy. If people want to understand them, they'll have to study. If people want to use them without understanding them on the conceptual level, that is eminently possible.
I myself don't understand monads and I've been using Haskell since 2005. I'm just not good at abstract algebra (flunked that class) and PDFs terrify me. However, even though if a mathematician asked me to explain monads I would be embarrassed, I can still use them and even define my own. That's because I've tinkered with them and acquired a know-how feel for the structure and what they are good for and how the patterns work—which is exactly how I've learned every other concept in programming.
Since most concepts in programming are ad-hoc, informal, and specified by hand waving, there is not even a possibility of understanding them at the level of mathematical rigor. What is an object? What is a class? Nobody knows. They just use them.
Or for that matter, the fact that it even is a problem, because it's easy to see that there are plenty of other programming languages with which people can do lots of productive things without ever thinking of the term "monad".
You can get away speaking English with a relatively compact vocabulary. But reading broadly to enrich your vocabulary with new words and idioms allows you to describe events more fluidly, and perhaps in a way which inspires you into better ways of describing the same thing you could have described less poetry in the compact vocab set. In that way words let you change your perspective by affecting how you frame your sense-data.
Mathematics is the same way. If you want to work in a variety of domains, you're going to have to be agnostic ahead of time as to what tools might be useful, which is to say, have many tools.
Learning in a vacuum is hard for all but the most abstract thinkers.
I personally find that bordering on impossible (and I still obtained a physics degree). I need a few examples of how a concept can be applied before it starts making sense.
At the moment I'm dabbling in image processing, and it wasn't until I had some visual explanations of morphology that it made a bit of sense. Now the maths has to follow on...
When designing programs or datastructures I prefer to use pen and paper and some simple set theoretic ad hoc notation system.
I write code for production daily and without this higher level design model my code would be uk terrible shape and very slow to modify.
"As a philosopher, it pains me to know people don't think that way, but if you aren't changing people's lives then all the theory is just mental masturbation."
Basically really good programmers seem to see the optimal structure for a specific problem out of practice. I need to have some sort of theoretic framework which to use to compose my program logic.
I've not had the time to look into category theory but this post succeeded in convincing me it's a practical mental tool to help in program composition.
So, based on my personal preferences, I disagree this would not have practical benefits.
I think the average OO programmer recognizes the value of design patterns, eg the Gang of Four book.
To quote Feynman incorrectly, Design patterns ala GoF are about as usable to programmers as ornithology is to birds.
> Design patterns ala GoF are about as usable to programmers as ornithology is to birds.
So here design patterns is compared to philosophy of science. I think of design patterns more as a toolbox than an inapplicable study of the art. Much like how math is essential for science, I feel that solid programming abstractions and patterns are essential for software development.
I don't think Haskell aims for this kind of success.
Abstractions can be useful and they can be beautiful. If your goal is to "easily build functional CRUD apps" you need the former. If you do research in computing science or would like to further your understanding or simply seek to appreciate the elegance and beauty in computation, you need the latter.
Admittedly, the latter goals (except research) are self-directed (they may make you a better or at least a happier programmer) and they don't directly contribute value to your customers, so I understand why you just called them "mental masturbation". However, I strongly disagree with that label. There is a long-term value in learning and general self-improvement.
The long-term wish as I see it would be for us as an engineering discipline to develop a really clear understanding of the domain, enough to be able to build these CRUD apps in composable ways that can be reasoned about with clear language.
Guiding vague questions might include: What is the essence of a CRUD app? How could you define a CRUD app in terms of sets, functions, and categories? What kinds of laws apply in the general CRUD domain? How can we statically verify correctness properties for real-world CRUD systems?
That hope has nothing to do with mental masturbation and everything to do with wanting to concretely improve the state of civilization. And of course to reduce the amount of time spent making and debugging the same kind of thing over and over again.
I find this way of reasoning incredibly powerful, because it tells me quickly what kind of transactions make sense in a business domain. Of course, this is contingent on the database being well designed. It is exactly the same as with Haskell types - if you can leverage the (type system) schema to encode interesting logical properties of your (problem) business domain, then (type checking) checking a query against the schema in itself becomes a lightweight form of formal verification.
One thing that must be remarked, however, is that, sadly, SQL lacks analogues of sum and product types, that is, tables whose cardinality (number of rows) is the sum or product of the cardinalities of other tables. This addition would make SQL even more powerful, but it would require a move to a more category-theory-based foundation for databases. (The relational model is based on first-order logic.)
So much so that I wonder if the popular monad tutorial involving spacesuits and burritos wasn't actually made as a pisstake (but I am 99% sure the author was serious).
Eh? Are you saying Sandy Metz isn't good, and needs DHH to provide a platform?
Disclosure: I have read POODR and am not sure what to make of it, as it's pragmatic but says the opposite of other OOP books I've read
>To the average person, a theory codifying a style into a pattern just isn't useful
But you don't mean "the average person", you mean "the average competent programmer."
For example I'm not an "average person" and I don't understand the sentence you linked (the one I quote at the top of this comment.) It's just gobbledegook to me, the way a bit mask is to someone who doesn't know what bits are exactly, they're just, like, 1's and 0's in the computer right? You have to explain a lot before they would even understand what you're talking about. They might not know what a power of 2 has to do with anything.
This is an analogy. It's the same - average competent programmers don't have this mental infrastructure. I and most competent programmers have no idea what a category is.
By your own admission, you have no idea whether or not category theory is useful to you.
Take pride in your ignorance if you like, but at least don't claim to know what you're talking about in the same breath.
There's a lot to learn from them.
I would add "just using a word from math is cargo cult". I just wish someone had told that to the 7 people who decided to use the word "static" for 7 different things ...
I've only recently gotten into FP, but to be honest, I prefer that to "use this design pattern, because design patterns", which is how things usually go, particularly in OOP. A lot of the "theory" in imperative programming seems four steps removed from the underlying theory (to the point where you can't really trace patterns to their underlying theoretical reasoning).
Sure, that often makes is easier to understand and utilize. To me, however, after 8 years of that, it's pretty sobering to start realizing just how much of your repertoire is cargo culting.
I would also argue that there is a huge difference in how the two worlds use, or even understand, design patterns. FP often puts you through the trouble of going back to basics (yes, sometimes even mathematical basics) and that can take enormous amounts of and effort. That's a level of discomfort and slowness I have come to appreciate.
why wouldn't it be useful in programming?
For some reason, category theorists often claim that category theory is "more fundamental" than set theory, whatever that means. It's especially bizarre since many category theory books begin by saying they will define categories without using sets, and then proceed to say "let A be a collection of dots, and B a collection of arrows" but only God knows what the difference between a collection and a set is, from what I can tell...
A positive side-effect of this avoidance of set axioms in the definition of a category is that we can more easily define categories with very different ideas of membership. For example, a category where membership is a real number (like in fuzzy logic). Categories with this idea of 'generalised membership' (plus a few extra bits and bobs) are called 'toposes', and can be used in much the same way as sets are. Importantly, we can relate different categories like this together using the same terminology and concepts and so more easily define ways to join classical code with fuzzy logic, or with neural networks (or anything else which satisfies the topos axioms) and know they're not insane.
Incidentally, you can define the axioms of a topos (and sets are a topos) in purely category theory terms. That is why some (and I'm one of them) view categories as a more useful foundation than set theory (where attempts to define the converse are much more messy).
So I disagree that a "set is more than a collection", with the qualification that the concept of a "collection" that is not associated with any axioms whatsoever, is meaningless. Why do I say "meaningless"? Because this "naive" concept of a collection leads to a number of logical paradox's that can only be resolved by using a system of axioms to define these collections.
So it's true that you can define sets by various axiom systems that are not the same, but these systems all exist under the umbrella of "set theory".
Using the "naive" concept of a collection is fair enough, since we all "know what you mean", but only as long as your point isn't that category theory is more fundamental than set theory.
My point is not that category theory is more fundamental than set theory (though set theory can be described in terms of categories), but rather that it isn't derivative. You don't need the formalisms of set theory to have category theory.
after learning a (little) more category theory and a (very little) more haskell, i think that assessment was inaccurate, and i wouldn't want anyone else to think the same thing.
haskell is strictly-typed, sugared lambda calculus. if you want to learnyouahaskell, think about types and type classes. learn how to desugar wheres, lets, guards, etc. don't worry about functors, much less monads.
> after learning a (little) more category theory and a (very little) more haskell, i think that assessment was inaccurate, and i wouldn't want anyone else to think the same thing.
Indeed. I work with some of the most highly-regarded Haskellers that exist. Few of them would claim they know much (or any?) category theory, nor do they care about category theory.
You absolutely do not need to know category theory to use Haskell effectively and productively. Once you've been using it for a while, though, you pretty much inevitably start learning (and caring about) the mathematics that underlies it.
Simon PJ, Simon Marlow, BoS, Lennart Augustsson, Don Stewart, Duncan Coutts, Neil Mitchell, Roman Leshchinsky
That hasn't stopped them producing masses of great Haskell.
I would welcome correction or clarification by any of the above luminaries!
The first, 'Computational Category Theory' by Rydeheard and Burstall, builds a library (in Standard ML) that allows one to construct objects that satisfy properties you care about (defined in category theory terms). For example, you could define a rules system in a fuzzy logic and have the right code be automatically generated using the library.
The second is less concrete, but probably more eyeopening. 'Category Theory for Computing Science' by Barr and Wells starts from the basic axioms of a category and ends with defining all sorts of interesting patterns for software modularity based on diagrammatic reasoning (a common tool in category theory for proving properties through simple pictures). The ideas here have helped me simplify and think more clearly about code I've been writing (in languages like Java, Python, and Ruby), even if the code isn't (ostensibly) categorical.
Two languages are defined, one total and one partial, with identical
syntax. The semantics of the partial language includes partial and infinite
values, and all types are lifted, including the function spaces. A partial
equivalence relation (PER) is then defined, the domain of which is the total
subset of the partial language. For types not containing function spaces the
PER relates equal values, and functions are related if they map related values
to related values. It is proved that if two closed terms have the same
semantics in the total language, then they have related semantics in the
partial language. It is also shown that the PER gives rise to a bicartesian
closed category which can be used to reason about values in the domain of the
relation.It says that (.) is the same thing as (>=>). Fine, but then why are we talking about (<=<) and (=<<) instead of (id) and (.) now?
While I somewhat have a noob understanding of Haskell, and some experience with monads, the parallels between composing functions (i.e. "id" & (.) ) and composing monads i.e. "return" & (<=<) never really occurred to me. Now that I've seen this, I'll probably start looking for similar patterns in other places.
This has been what made Haskell click for me: the minute you start doing something that is slightly repetitive, like a for loop including a continue/break, parallelizing code or using if error/null all the time, there's a pattern there. Haskellers recognize these patterns, and implement them once, so you can reuse them and avoid making mistakes by implementing something similar yourself every single time. Having this opportunity makes your code more shorter and concise, and instead of implementing something yourself, you can use these battle-tested implementations to model your code. (And thus avoid those annoying not-null/if error bugs for example.)
Even though Haskell might not be suitable for every problem domain, I found out it really shines by it's explicitness. You model your domain using types for intermediate states, and the exercise of converting one type to another is rather trivial. (f.e. a sudoku solver [3]).
The biggest problem for me personally has been my inability to speak the category theory language, but I'm learning... I also believe that the basic Haskell libs need examples next to their descriptions, because most of us learn by example. [1] If I can see what a maybe monad is for, I can start using it without properly understanding monads. After a while you'll have seen enough different types of monads to understand their use case. IMO one language implementer that understood this extremely well is José Valim, just take a look at the Elixir docs for data.list. [2]
Because Haskell has been mostly implemented by mathematicians and computer scientists, they assume basic upfront knowledge. This is what makes it hard for beginners. What we really need in the Haskell world is some cognitive bias mitigation. YMMV.
* [1]: https://www.reddit.com/r/haskell/comments/3rhpyq/as_a_haskel... * [2]: http://elixir-lang.org/docs/stable/elixir/List.html#function... * [3]: https://github.com/ToJans/learninghaskell/blob/master/0003%2...
We should be looking for more ideas that make programming better with minimal learning cost. Examples of such ideas that were wildly successful in the past: garbage collection, modules and imports, Unicode strings. Each of those was justified by practice rather than theory.
Let's talk about functions. Why is id . f = f . id = f? id . f is a function which takes some argument, pushes it on the stack, calls f, pushes the result from f on the stack and calls id. This is two function calls and you go two stack levels deep. Just f is one function call and one stack level deep. If f and id are real functions executing on real hardware, then id . f is not strictly equal to f due to unavoidable side effects even if id and f are both pure functions, e.g. you may have not enough stack space to execute id . f, but you could execute just f. Real functions executing on real hardware aren't exactly the same like the pure mathematical notion of a function. If Haskell is a language for writing computer programs executing on actual computers, then id . f ≠ f; and if it isn't, then it's not very useful.
Abstractions are well and good, but I must be able to reason how the machine will work while executing my program. Take the official Python implementation - CPython for example. It's nowhere near as fast as C if you write your code naively, but there is very little surprising about it. Or take C. If you write e.g.
int id(int x) { return x; }
int f(int x) { return 2*x; }
int id_f(int x) { return id(f(x)); }
Then the compiler is free to compile id to a noop and id_f to be exactly the same as f, but it is not required. Most people won't write a program which requires that behaviour by the compiler in order to work correctly.If the Haskell compiler is required to perform such optimisations, then I would concede id . f = f; just like tail recursion optimisation is required in Scheme, so tail recursion is actually equivalent to loops, rather than being just mathematically equivalent.
The broader point I want to make is that a computer programming language is inescapably tied to the reality of how hardware executes instructions and one must have some guarantees on how what is written will translate to machine execution.
Another thing is that once you reach a certain level of abstraction, you lose your ability to reason about the concrete things in that class. I'll illustrate what I mean.
Let's construct the set of Handleds. A handled is a thing that has a handle, and a handle is a cylindrical protrusion affixed to the object, that can be grasped by an average adult human hand and pushed or pulled along an axis perpendicular to the cylinder's height. So, a TNT detonation device is a handled, since you have a handle on the plunger you press to detonate the TNT. A door also has a handle. Your laptop bag has a handle. A table leg also technically counts as a handle and you can use it to move the table. The thing is, while you would have a theory on how to make handles, such that they would be easily operated by people, the fact that an object has a handle tells you nothing of the object, other than it can be manipulated with a hand.
Pretty much the same goes for a category. Yes, you can compose two elements of the category into a third. So... what does it do? You don't know. The problem is, the two lumps of fat that sit in your skull need to affix some concrete properties on the object in order to think about it. Functions are series of instructions that transform values. Or maybe they're relations, if you're a mathematician. But the essence of a function isn't in its composability (at least for programmers), it's in its usage as a unit of execution. Maybe also in its usage as a way to organise your source code.
There's no point in explaining something as "it's a category" any more than in a car salesman starting out by pointing all the handles on the car and how the bumpers can be grabbed as ersatz handles in case you need to get a handle on the situation. Saying something is a category is a deferred meaning that you can only understand once you know what that something is, so it's more of a mental burden than an explanation of anything.
Category properties may be simple, but their relation to the actual execution of a program is anything but. If you want to explain Haskell, maybe start off with the simple parts. Like how what you write executes on the actual machine and work your way up.
Presumably you don't object to the notion that sin(a + b) = sin(a) cos(b) + cos(a) sin(b), even though the left and right hand sides are totally different in terms of computation.
That's because you know that such identities, while indeed abstracting over computational details, have real meaning and are extremely useful in mathematical thought (and algorithm design; you can use that equation to implement an efficient numeric oscillator).
Given that you probably accept that trigonometric equality, you can't really dismiss equational reasoning in software as useless just because it abstracts over stack frames and machine instructions. That kind of abstraction is exactly the point.
Most categories that arise in practice aren't “just” categories - they have interesting extra structure. For instance, platonic Hask, the category of Haskell types and total functions, is bi-Cartesian-closed. The categories that arise when modeling databases are typically not closed (from a programmer's POV, this means that functions aren't first-class objects - you can't store them in tables), but they have finite coproducts (UNION ALL) and products (SELECT ... FROM multiple, tables). SQL-style aggregate functions are nothing but commutative monoid objects in these categories. etc.