142 points · by Tehnix · 10y ago · 116 comments
But once the core abstractions are settled, you start to reap its power. The type system catches tons of potential errors. Combinators allow for enormous expressiveness. Here you're rolling: Haskell is in its zone!
But then you hit a wall. Laziness makes for brutal debugging. Singly linked lists actually suck. Performance optimization is a black art. You find yourself longing for a language with simple semantics and mechanical sympathy. Now Haskell is bumping up against the real world.
Haskell has its sweet spot somewhere between "bang this out by 5pm" and "ship this to a million users". (No surprise it's popular in academia.)
The opposite is true: here Haskell helps to find the right data structures/abstractions incredibly fast. The ability to quickly construct and reconstruct a high-level skeleton of your program without actually having to implement anything makes prototyping much easier and faster than in comparable dynamic languages.
> But then you hit a wall. Laziness makes for brutal debugging.
Laziness can sometimes surprise you in bad ways, but it's not like it's impossible to debug.
> Singly linked lists actually suck.
Just replace them with the right data structure then? Even for big codebases and fundamental program abstractions that's a 15min job, because of types.
> Performance optimization is a black art.
I agree. But then again - you don't have to write everything in Haskell. Writing the critical 1% in C, testing the shit out of it and calling it from Haskell is absolutely fine.
> Laziness can sometimes surprise you in bad ways, but it's not like it's impossible to debug.
The last message I get was something like "Array.Array: Index out of bounds". Program crashed. No idea where the error originated. The answer I got was "yeah, in GHC 8 there will be some support for stack traces".
This is much faster than writing a large chunk of code, playing around in the REPL thinking everything is ok, only to realize one week later that you didn't think through some core aspect of your design and then having to refactor a sizeable piece of your codebase.
> The last message I get was something like "Array.Array: Index out of bounds". Program crashed. No idea where the error originated.
It is an unfortunate historical artefact that there are still partial functions (i.e. functions that may crash) in the Haskell base libraries. It is generally advised to avoid such functions, but this is not very clearly communicated to newcomers to Haskell.
For example, Elm, a language largely inspired by Haskell, doesn't have partial functions. This is why it prides itself in "not having any runtime errors in production" (excluding things like compiler bugs or unsafe JavaScript libraries, of course).
THAT is where Haskell shines, the ability to refactor and expand fearlessly and aggressively.
I think for large or complex programs Haskell is much faster for constructing a skeleton because it's usually not the logical operations that trip us programmers up, it's the data flow and correct alignment of types, which are implicit in a dynamically typed language and explicit in Haskell.
So, it's kinda-sorta like writing your ideas down in a structured language which enables you to "see" the abstractions in a rigorous light, then the ability to refactor aggressively and safely kicks in so once you can see your abstractions you can quickly adapt for better ones.
So I think the initial work is made quicker in that it forces you to excogitate then because it's in some concrete form you can see it clearly and take advantage of quick turnaround time in refactoring.
To be fair, these issue are more-or-less solved by newer functional languages, such as OCaml or Rust.
Also, OCaml is still two decades old. I find it very bizarre that you attempted to group it in with Rust as a "new" language.
Well, even then, Rust does not only give you control over execution order, but also tight control over memory management, while keeping it safe.
Haskell allows for good reasoning about correctness. In OCaml, you can additionally reason about execution order, but memory management and garbage collector are still somewhat "unpredictable" (i.e. hard to reason about). On top of that, in Rust, you can reason clearly about memory usage and aliasing.
These new, modern languages follow a clear path about keeping quality and correctness (hence safety) while having more and more control over performance, without going back to low-level where you would loose clarity about correctness and safety.
(Note, however, that the distinction between correctness and performance is over-simplified here, because performance can also be part of correctness, e.g. for real-time systems, or in systems where scalability is an important requirement.)
This is so true. Once you get the types settled for your project, then it becomes a breeze to quickly add things and refactor over and over again, because maybe the spec or idea changed.
I've recently experienced this in both a Haskell project (using the Yesod framework) and I'm currently working on an Elm project, where I very much feel this strength also.
I'll have to agree with you on the debugging though - it is somewhat of an art, and not one I've completely mastered yet, since I haven't had that much need for it for now (haven't done that many production haskell projects).
There's some evidence Haskell is pretty good at rapid prototyping.
Are you familiar with this '94 paper on rapid prototyping [ http://www.cs.yale.edu/publications/techreports/tr1049.pdf ] by Paul Hudak (RIP), sponsored by the Office of Naval Research & ARPA? The paper is a report on an experimental comparison of programmming languages for prototyping, and it's pretty cool because they were asked to implement a portion of a (heavily simplified) AEGIS weapons system! Unfortunately the paper and experiment are dated and have a number of methodological shortcomings (results were self reported; the examining panel didn't look at running code; requirements were very vague and mostly determined by each team, which makes the comparison difficult), but the results are pretty interesting regardless:
- Of all the teams, only the two Haskell teams delivered working code (though the examiners didn't look at working programs). This must be stressed: no other team delivered running code at all, much less on time!
- One of the Haskell prototypes delivered more features than the initial requirements asked for.
- The programmer of one of the Haskell teams had NO experience with Haskell before the experiment.
- Both Haskell prototypes were also the shortest in line count. Way shorter than the C++ prototype, which wasn't even finished or working in time!
I'd like to see the same experiment repeated under more rigorous conditions and with more modern languages, but the results certainly hint at Haskell being more than adequate at prototyping.
Of course, today it would have to go toe to toe against modern dynamic languages. In this case it'd be essential to demonstrate running code, which is arguably a huge advantage of static typing over dynamic typing; if you're only comparing source code, dynamic languages can get away with being terse and claiming "trust me, it works".
I imagine Haskell would still leave modern C++ coughing dust at the start line :)
“Simple semantics” as measured how? The only good metric I can think of is the size of a formal specification.
Not so ago there was some discussion about "batteries" included with Haskell. [1] It compared situation of Haskell with that of Python/Java etc, worth reading if you are about to go the Haskell route.
It seems, the priorities (academic, commercial, library support and so on) of the members of Haskell community are at crossroads and they cannot seem to resolve those very good, IMHO.
My take: Haskell is good for learning some really deep concepts, but may be not so good when it comes to commercial projects, unless you are a Haskell veteran and also have an army of Haskell veterans with you.
[1] http://osdir.com/ml/haskell-cafe@haskell.org/2016-10/msg0001...
https://github.com/Gabriel439/post-rfc/blob/master/sotu.md
Which backs up your statements; many of the sections under "Common Programming Needs" are rated immature: Databases, Debugging, IDEs...
I'm not saying everything is great with Haskell, but so far, I haven't run into major holes for what I'm doing, library-wise.
Is it rigorous in theory or in practice?
An academic veteran might want to better express his ideas in code while a professional veteran might want more readable code with better test coverage. And that's just 1 axis where the two viewpoints might diverge or even come in conflict.
Have we actually seen that or have you just asserted that? Is this really true, and if it is, by how much? Haskell has been around for a couple of decades now, and has had least two hype cycles (I remember that when I was in university in the late '90s, Haskell was the next big thing). It does not seem to expand significantly even within organizations that have tried it (and that's a very negative signal), with at least one notable case where the language has been abandoned by a company that was among the flagship adopters.
In general, we know that often linguistic abstractions that seem like a good idea in theory -- or even seem to work nicely in small programs -- don't end up having a significant effect on the bottom line when larger software is concerned. People say that scientific evidence of actual contribution is hard to collect, but we don't even have well-researched anecdotes. Not only do we not have strong evidence in favor of this hypothesis, but there aren't even promising hints. All we do have is people who really like Haskell based on its aesthetics and really wish that the the nice theoretical arguments translated to significant bottom-line gains.
This blog post by Dan Ghica, a PL researcher, really addresses this point: there is nothing to suggest that aesthetically nice theory translates to actual software development gains, and wishful thinking (or personal affinity) simply cannot replace gathering of data: http://danghica.blogspot.com/2016/09/what-else-are-we-gettin...
Although the study in the paper isn't very practical, it's still an interesting experiment.
I'll settle for well-researched case studies.
> there is a related paper regarding that
That's a step in the right direction, but the paper doesn't discuss software development, but prototyping. We know that "theoretically aesthetic" languages do well in specification and prototyping.
Don't know if it helps, but they have some case studies here https://www.fpcomplete.com/case-studies.
The same can be said about nearly every language. Haskell is first and foremost a research language motivated by answering a research questions, which is what it is like to program using a certain mathematical formalism that is aesthetically appealing to some. Its designers didn't set out to find the best abstractions etc., but to test the validity of a specific theoretical approach.
> but to that I would say don't knock it until you have tried it.
I'm not knocking it. I'm saying that given how expensive it is to try, perhaps some actual information rather than marketing would do a better job in persuading people to use it. Saying that I'm not persuaded by virtually zero information is no knocking anything, except perhaps the advocacy effort.
> The same can be said about nearly every language.
This clearly isn't true. For example many languages optimise for ease of use, shallow learning curve, programming in the small etc. Some optimise for efficiency and runtime determinism. Features like type-systems are great for software development (programming in the large), but do negatively impact ease-of-use.
> Haskell is first and foremost a research language motivated by answering a research questions
This isn't true. The Haskell committee contains many people from industry. Haskell just happens to have come from academia and is still heavily used in academia.
> Saying that I'm not persuaded by virtually zero information is no knocking anything
That's a huge exaggeration to suggest there is zero information. There are many experience reports published all the time at conferences and in academic journals, going back decades. None however will give you the quantitative metrics you seem to be asking for, because it is almost impossible to do such a comparison.
I'd say they have probably seen it. The author of the post himself works at FPComplete, and they use Haskell for their consulting business. That and there are some case studies on their site (I'm fairly sure they all have experience in other languages too).
How can you be sure? Have you seen Haskell shops churn out software significantly faster than others?
I would have liked to see a comparison to other functional languages (say Elixir or OCaml) and not just Java and C#. I'd also argue that picking Java instead of a more agile environment (there are some cool lightweight Java frameworks but most people will associate it with the rather heavy enterprise stack) when comparing regarding time to market is a bit odd. Granted I'm mostly thinking about webapps (but the article mentions Yesode).
Still a nice article (since my post sounds overly negative upon rereading).
Well, the best language for an early-stage business is the one the founder knows, but that's always going to be true. There's no reason that language can't be Haskell.
Having said that, Time-to-Market is only partially influenced by my-code, the biggest part is the code that I don't have to write, i.e. third-party libraries.
In my Haskell adventures I am having trouble finding third-party libraries for even the most popular things, e.g. Cassandra. As far as I can tell there are two libraries, the `cassandra-cql` and the `cql-io`, the first hasn't been updated for a year now, and the second has only 3 stars, which makes me uneasy.
So, although I can see where the author is coming from, I don't think you can beat Java, Ruby, JS or Python in that sense. Unless of course your code/project doesn't have a lot of dependencies.
It's some incredibly productive yak shaving, it's even fun, but it's still yak shaving.
But I'll point that Haskell has also many wonderful libraries, for stuff you won't see in other communities. The libraries that are available are of an unmatched quality. Odds are a library marked as experimental on Hackage is more reliable than a mature one on the Python Index.
F# looks like a more pragmatic choice, and I've been looking hard for a good place to bite off to use it going forward. But again, it'll be bad for the bus factor.
So the best option I've found is to just start using more functional concepts and patterns in Java/C#. C# in particular seems to be leaning in this direction with the features added in the latest language versions.
https://m.reddit.com/r/rust/comments/5dtfp2/haskell_more_pro...
(Tried to ask on HN first, which once again proves the value of subreddits, as small focused communities: https://news.ycombinator.com/item?id=12989041)
This is not going to change.
I love Haskell, and I appreciate the effort many are making to evangelize the language, but I am experienced (ie. cynical) enough to believe that it's never going to become truly mainstream.
Clojure is quite quick to write and time to market can be very fast, as with most lisps, but you pay the price at debug time. We recently shipped a production app that had a small typo that the compiler would have easily caught, but instead it crashed the site when this one particular task was run.
What was the typo?
> it crashed the site when this one particular task was run.
Might that also be because that was the first time the task was run at all, since the code was written or altered?
Code that compiles (such that we are confident it is probably free of silly typos, other than those somewhat rare typos which play out in some way that still compiles), might not be correct; it still requires testing.
Maybe with F# author would see decrease of development time compared to Haskell?
There is more professional work being done in Scala, and it makes it more palatable to managers that it runs on the JVM and allows them to leverage some of the existing knowledge of their Java programmers.
In the financial world, however, F# use is on the rise.
I currently work in F# but not in finance, and the lack of mature libraries for common things (like JSON serialization!) makes it a major pain in the behind.
Were I told to select a functional language, "quick!", I would select Clojure when caffeinated, and Javascript (ES7) when not.
FWIW: I subscribe to the notion that dynamic typing with unit testing will get you a correct and working program faster than static typing. In the case of Clojure, you now have clojure.spec, which means you can write conformance criteria as functions and generate tests and test data.
http://games.greggman.com/game/dynamic-typing-static-typing/
[1]: https://www.coursera.org/specializations/scalaIf you're looking for enlightenment, pick up Haskell, maybe OCaml and skip F#.
Short answer: whichever you can get a job in. That's more important than the design differences between them, which are relatively small.
Long answer: I wouldn't use F# because nice as it is you're eventually going to want HKT. Between Scala and Haskell I'd pick based on your learning style - Scala lets you write familiar comfortable code and incrementally adopt functional features, Haskell forces you to dive straight in and do things the Right Way from the start.
Having gone down the Haskell rathole, it's clear to me that the advertising is better than the product. It's complex and difficult to learn and the "less errors because of typing" mantra turns into 'how in the world am I supposed to find my error'. In practice, I very rarely run into errors caused by type problems.
I know nothing about F#, but that's actually my criticism of it. The F# community is small. I occasionally hear about people playing with F#, but even that is rare. (although it could be that I just don't know enough about it and F# and it's community is awesome)
Scala has a reasonably sized community and is being used in production plenty. I personally don't see any benefit beyond the fact that some people like the syntax better than Java and can do less boilerplate (which, if not paying attention could lead to higher resource consumption).
If I were looking for something new, I'd look into Go and Rust. Both have strong followings, a lot of active development to learn from, and strong job markets moving forward (IMO). Or alternatively reverse-expand back into C and start playing with embedded RTOSs - which has the benefit of both being very interesting and an area where senior people could make a significant impact.
... Now, if you really wanted one of the three - I would choose Haskell for learning, Scala for job market, F# if you are already a .net developer.
However, Haskell and OCaml are the more classic functional, static-typed languages, and while Haskell has more job opportunities than OCaml, it is probably the steepest learning curve and highest time commitment of all these languages.