Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the fuss about Haskell? [closed]

People also ask

Why is Haskell not popular?

The reason is quite obvious. The facilities and elegance of Haskell are very different from the needs of most mainstream programming. Haskell just isn't the right tool for these jobs. One of the most common patterns in popular programming is runtime polymorphism.

Is Haskell Worth learning 2022?

Is Haskell Worth Learning in 2022? Yes, Haskell is worth learning in 2022 because functional languages like it are getting more popular among big companies like Facebook. Functional languages are typically ideal for big data and machine learning.

Does anyone actually use Haskell?

Firstly, Haskell is still primarily used in academia and research. There are companies that use it (see list above) however, even they struggle to find good candidates that have experience. It can be rather complex and so not a lot of new programmers will try to learn it.

What's the point of Haskell?

Haskell is the main technology that helps us deliver high quality software. There are various criteria to judge software quality, but the most important ones are correctness, performance, and maintainability. Haskell facilitates writing code that scores high on all of these accounts: Correctness.


This is the example that convinced me to learn Haskell (and boy am I glad I did).

-- program to copy a file --
import System.Environment

main = do
         --read command-line arguments
         [file1, file2] <- getArgs

         --copy file contents
         str <- readFile file1
         writeFile file2 str

OK, it's a short, readable program. In that sense it's better than a C program. But how is this so different from (say) a Python program with a very similar structure?

The answer is lazy evaluation. In most languages (even some functional ones), a program structured like the one above would result in the entire file being loaded into memory, and then written out again under a new name.

Haskell is "lazy". It doesn't calculate things until it needs to, and by extension doesn't calculate things it never needs. For instance, if you were to remove the writeFile line, Haskell wouldn't bother reading anything from the file in the first place.

As it is, Haskell realises that the writeFile depends on the readFile, and so is able to optimise this data path.

While the results are compiler-dependent, what will typically happen when you run the above program is this: the program reads a block (say 8KB) of the first file, then writes it to the second file, then reads another block from the first file, and writes it to the second file, and so on. (Try running strace on it!)

... which looks a lot like what the efficient C implementation of a file copy would do.

So, Haskell lets you write compact, readable programs - often without sacrificing a lot of performance.

Another thing I must add is that Haskell simply makes it difficult to write buggy programs. The amazing type system, lack of side-effects, and of course the compactness of Haskell code reduces bugs for at least three reasons:

  1. Better program design. Reduced complexity leads to fewer logic errors.

  2. Compact code. Fewer lines for bugs to exist on.

  3. Compile errors. Lots of bugs just aren't valid Haskell.

Haskell isn't for everyone. But everyone should give it a try.


The way it was pitched to me, and what I think is true after having worked on learning on Haskell for a month now, is the fact that functional programming twists your brain in interesting ways: it forces you to think about familiar problems in different ways: instead of loops, think in maps and folds and filters, etc. In general, if you have more than one perspective on a problem, it makes you better enabled to reason about this problem, and switch viewpoints as necessary.

The other really neat thing about Haskell is its type system. It's strictly typed, but the type inference engine makes it feel like a Python program that magically tells you when you've done a stupid type-related mistake. Haskell's error messages in this regard are somewhat lacking, but as you get more acquainted with the language you'll say to yourself: this is what typing is supposed to be!


You are kind of asking the wrong question.

Haskell is not a language where you go look at a few cool examples and go "aha, I see now, that's what makes it good!"

It's more like, we have all these other programming languages, and they're all more or less similar, and then there's Haskell which is totally different and wacky in a way that's totally awesome once you get used to the wackiness. But the problem is, it takes quite a while to acclimate to the wackiness. Things that set Haskell apart from almost any other even-semi-mainstream language:

  • Lazy evaluation
  • No side effects (everything is pure, IO/etc happens via monads)
  • Incredibly expressive static type system

as well as some other aspects that are different from many mainstream languages (but shared by some):

  • functional
  • significant whitespace
  • type inferred

As some other posters have answered, the combination of all these features means that you think about programming in an entirely different way. And so it's hard to come up with an example (or set of examples) that adequately communicates this to Joe-mainstream-programmer. It's an experiential thing. (To make an analogy, I can show you photos of my 1970 trip to China, but after seeing the photos, you still won't know what it was like to have lived there during that time. Similarly, I can show you a Haskell 'quicksort', but you still won't know what it means to be a Haskeller.)


What really sets Haskell apart is the effort it goes to in its design to enforce functional programming. You can program in a functional style in pretty much any language, but it's all too easy to abandon at the first convenience. Haskell does not allow you to abandon functional programming, so you must take it to its logical conclusion, which is a final program that is easier to reason about, and sidesteps a whole class of the thorniest types of bugs.

When it comes to writing a program for real world use, you may find Haskell lacking in some practical fashion, but your final solution will be better for having known Haskell to begin with. I'm definitely not there yet, but so far learning Haskell has been much more enlightening than say, Lisp was in college.


Part of the fuss is that purity and static typing enable for parallelism combined with aggressive optimisations. Parallel languages are hot now with multicore being a bit disruptive.

Haskell gives you more options for parallelism than pretty much any general purpose language, along with a fast, native code compiler. There is really no competition with this kind of support for parallel styles:

  • semi-implicit parallelism via thread sparks
  • explicit threads
  • data parallel arrays
  • actors and message passing
  • transactional memory

So if you care about making your multicore work, Haskell has something to say. A great place to start is with Simon Peyton Jones' tutorial on parallel and concurrent programming in Haskell.