by ilovecaching · 4y ago · 0 comments
I think that it’s an interesting side hustle and if people enjoy playing with it more power to them, but most of Haskell is driven by language enthusiasts and researchers who have no eye for practicality. Everything is done for its own sake, such as whether something can be done through derivation via HKTs etc. A lot of it comes down to it being an excuse to play with math rather than write programs. The way that it’s oversold as the solution to all bugs is based on an understanding of society that doesn’t match with reality, nor the needs of the modern programmer.
So what is an IO Monad? It’s a clever trap to get you to spend your time getting a poor man’s degree in category theory when you could be studying how computers really work.
But I suppose it depends on the environment you end up with. All the Java I did was with people where you could get away with murder in the code. All the Haskell I did was with people who carefully consider network failure, memory usage, readability, timeouts, pathological logging loops, etc., and would push back on code that isn't easy to use, maintain, and troubleshoot.
I understand why Haskell will never become the language of industry. Lazy evaluation, a hundred and one extensions, the fact you would need to retrain everybody... but I'm not really interested in that. Haskell is a place for ideas, not really practicality. This has been gone over time and again.
The reason I use Haskell for personal projects is because they all end up being very few lines of code compared to imperative versions, and it usually just works. For me that's enough benefit to learn it.
It would be nice if an ML language actually became popular at some point. But that won't be for a long time.
This is the entire problem with Haskell. This isn't the reality we live in. In our world there's a concrete need to understand performance at the level of the hardware and the kernel. Let's not even talk about compilers, which have to make many tradeoffs and often produce sub-optimal code without human guidance. The kernel itself doesn't always make the right decisions on where to place workloads, how to balance IRQs, moving tasks between cores, etc.
If you want to become a better software engineer, learn how your computer actually runs code, don't learn Haskell.
Edit:
It's not letting me respond to your reply directly, so here is my reply:
We all have different experiences in the industry, but my experience has been that I often need to diagnose and solve performance issues that involve using perf, ftrace, bpf, pprof, etc. I'm not saying we should all write C, I'm saying that you need to know how to look under the hood when you're using a language that does more work for you. Understanding how to look under the hood (again this is my experience) and know what you're looking at is far more important than mastering high level language concepts. You can change out the language, but the kernel, hardware, etc. remain the same. It's also important to understand these things because security is only becoming more important and attackers exploit the gaps in your knowledge. Spectre was a huge deal and it requires an understanding of how a pipeline works, how your program interacts with the cache, etc. If I ask you how to find out how may instructions your program ran, how many branches it took, how many branch mispredicts there were, if it was exhibiting false sharing, etc. could you tell me? You can't optimize something or know if you're being attacked if you don't understand how things work or what the baselines are.
Going by what you've said, it sounds like you want the industry to return to C/C++ for everything.
As for Haskell, I'm not experienced enough to make a real defense of it, but I've been told the compiler is pretty damn good. It's a decently fast language. I don't know how it compares to something like Go, and of course for very high-performance needs you probably shouldn't use it, but letting it take over isn't the worst thing in the world, and you can still use knowledge of hardware to make it faster.
But if that's not enough, just use Rust or something. It's basically Haskell-lite anyway.
You're thinking in terms of languages and not systems. If you've ever built systems at scale, you'll know that abstractions break down. The best of us write leaky abstractions. When the time comes to debug a leaky abstraction, you need to open up the hood. This means checking how many connections are open, checking whether you're flushing too often to disk, checking if your DB queries are locking up tables, checking when you're thrashing CPU, checking if you're not pooling a connection properly, etc. That's when you need to break down the abstraction layers and break out tools like iperf or Wireshark.
Languages like Haskell create such a different execution model (with monads and lazy execution) that it makes it really hard to break through its abstractions and understand what's going on.
I've had similar experiences to the author. I've written Haskell for fun and worked in Scala. Most of the folks who have your viewpoint have (in my experience) not worked in a situation where these issues come up. Either the scale of the problem is low so powerful abstractions are more powerful than deconstructing them or they work in problem domains where standards around correctness are a lot lower and programmer happiness is paramount. But if you've ever been in a position where you need to write a high-scale or high-reliability application, languages with highly abstract execution models prove more a liability than an asset. In that regard both Erlang and Rust offer a much more concrete execution model that's a lot easier to reason about than Haskell or monadic Scala offers, at least in my experience.
Haskell is a top down language. It is an abstraction over a variation of typed lambda calculus. The compiler compiles haskell into this lambda calculus and then has to figure out how to efficiently evaluate the terms. One can argue that with a "sufficiently smart compiler" it can make things run fast. Unfortunately, this is not really the case and it is not easy to reason what code is being generated for what you write. Are optimizations like deforestation kicking in? There are also plenty of abstractions that the Haskell community gets excited over even though they come with performance impacts. These abstractions may be entertaining, but they are not necessarily practical. If you go deeper in the rabbit hole of FP you might find people talking about how with homotopy type theory a compiler could recognize code and substitute it with a more "optimal" version. Unfortunately, a mythical "sufficiently smart compiler" does not exist and even if it did the compile time would be impacted in trying to optimize your programs.
The "how computers really work" argument is that languages should instead be abstractions over the CPU (or other hardware devices) instead of abstraction over computation itself (alternatively you could also see it as an abstraction over graph reduction based hardware but since we aren't running it on such hardware that is problematic). In the real world we have real concerns about resource usages such as processing time and memory. Abstractions over the CPU makes it easier to have a general idea on what the code that is being generated looks like.
It may be the case that your use case is not that sensitive to performance or memory usage so continue to have fun using Haskell. As you said Haskell is "not really practical." To your point of Haskell having very few lines of code compared to imperative version I feel that is likely just a matter of what is in the standard library / what libraries you used.
Sure, you can express nigh everything in C++, but defaults matter — a parallel algorithm may well be in the “worth it to implement” category for Haskell, and be in the “no way that we can make it work” category for some lower level language.
Don’t get me wrong, sure, the memory model of haskell may also not be the best which has probably the biggest performance impact, but I really don’t think that there is as much of a difference between comparable high level languages to haskell, so it can absolutely be a good choice for certain applications.
It is still largely serial. If you are concerned about the dependencies of the actual instructions themselves (since the CPU can use this information to execute multiple instructions at the same time) in order to optimize something you will be very concerned about being able to predict / look at / influence the code generation.
>a parallel algorithm may well be in the “worth it to implement” category for Haskell
>“no way that we can make it work” category for some lower level language.
I disagree. It is mainly a matter of having libraries available that makes it easy. If a library was made for Haskell that makes parallel algorithms easy to implement a similar library could be made for C++ or whatever to do the same thing.
In a world where CPU is infinitely fast and has infinitely large RAM
How do you explain the use of Haskell or Haskell-like languages in High Frequency Trading?
Haskell is being used in the industry with great success, yet this myth continues that it can only be used in academia. Puzzling.
The issue with your POV is, IMO, that you lack imagination for how vast the industry really is. There are millions of problems that are being solved with Python, PHP, Java, you name it, that can as well be done with Haskell. And constraining those solutions through the lens of "how computers really work" is unpractical, theoretical BS.
And funnily enough, the time I've spent really learning shell/awk/sed (pretty much the exact opposite of Haskell!) was one of the best investments of my career!
I also almost mentioned that I think language extensions are one of the things that hold it back the most from being more than a research project. But deciding what set of extensions are needed to make the language practical is probably a difficult problem for anyone to solve.
If you mean for the compiler writer, sure, C is very practical for someone who wants to make a compiler. But I'm afraid people might read your comment as saying C is practical for writing applications.
I wonder what is your view on functions and local variables? Do you find structuring programs with them useful or just an academic exercise?
I had the "privilege" to work with assembler programs, written in 1970s and 1980s, that were mostly one big procedure, with a huge bunch of shared global variables. Back then, it was very efficient way to program (that's why it was used), and down to metal. But it was unmaintainable mess.
(And that's what we want from a compiler - to transform program from maintainable and somewhat abstract description down to unmaintainable spaghetti that can be, however, executed very efficiently.)
Pure functional programs are just taking it step further, saying that most functions shouldn't need full access to their execution environment (operating system). The result is, supposedly, even more maintainable programs.
But let’s take a compiler backend or a JIT compiler — you may very well need much more powerful abstractions for these, and having the language help you with that can be a huge boost. In this area, the concepts you may have learned would definitely apply much more often.