HACKER Q&A
📣 jamesdco

Why would anyone choose Haskell to develop applications?


Why would anyone choose Haskell to develop applications? Does it offer any actual practical benefits over other languages?


  👤 pengstrom Accepted Answer ✓
When I asked my current employer why they chose it, they simply responded that it attracts the "right" people. From a business perspective, any language is arbitrary. What matters is having clever people around to solve problems.

👤 sillysaurusx
You’re in luck. I prepared an entire thread on this subject, as someone who was forced to learn it by necessity rather than by choice. https://twitter.com/theshawwn/status/1490237220950876161?s=2...

I’ll come out and say it though: Haskell is a cult. It’s best to smile and nod when you’re around the believers. They’re harmless. Ditto for rust.

It is truly astonishing how much code a determined team of haskellers can produce. I’ve been porting a codebase, line by line, to python. I’m up to 15 thousand lines.

Had to do it without being able to run the program too.

There are lots of benefits. (Ditto for being in a cult.) It’s worth knowing what they are, since they are powerful. But (hello cult) there are plenty of negatives; monads are the Aristotle philosophy equivalent of programming. Take care not to study them too closely.


👤 omnibs
It's an expressive, pure, statically typed functional programming language with a large enough package registry, community and optimized enough runtime/compiler.

Breaking down the benefits of each:

- Expressive: you can model things with greater fidelity

- Pure: you know when your code performs side effects, so you're in for fewer surprises

- Statically typed: you learn about things at compile time, not in production. You also need to write fewer tests.

- Large pkg registry: fewer things to implement yourself (compared to, say, Idris)

- Large community: fewer problems you'll be the first one to discover/solve

- Optimized enough compiler: compile times can be _acceptable_

- Optimized enough runtime: your app will be fast enough without you having to care much about it

Now one point that isn't obvious from all this and that is a big selling point for my company is how much of a breeze refactoring is. Types give you more guarantees around how your code behaves, so there's classes of mistakes you can't make, and won't have to rely on a super strict test suite to prevent you from making.

Newhire submitting a PR changing 25 files all over the codebase? Business as usual.


👤 tluyben2
It is very easy to build languages, dsls and compilers in. A lot of language writers at least build a first version or prototype in it. I like it because in my head, all programming is just moving data from one type to another and although this is possible in any language, Haskell and also Idris 2 fit my mental model well. Unfortunately when I have to work with other humans, Haskell never makes the cut, so I only built side projects in it.

👤 thesz
Haskell allows to build abstractions that are less leaky than in most other languages.

Take a vector package, for example. It provides you with unboxed vectors that are structure-of-arrays by default with the interface of array-of-structures. That means you can have fast slicing operations in both dimensions - slice by field and/or by indices. Of course you can have unboxed array-of-structure arrays, if you need them, they are there too. But their use is transparent to you as user, however your choice is.

Same is for other interesting structures.

Say you wrote your parsing library. You can provide a rule to compiler such that code "(pchar c `pthen` p1) <|> (pchar c `pthen` p2)" is equivalent to "pchar c `pthen` (p1 <|> p2)" and you get left factorization for all your grammars supported by compiler.

Parallelization is often as far away as adding a par/pseq annotation.

Haskell can remove intermediate lists and fuse mapping over complex structures such as red-black trees - it is done for all of your code so when you do "fmap f (fmap g) rbTree" you will get "fmap (f . g) rbTree" and compiler will try to get you that code by transforming your code where "fmap f" can be pretty far away from "fmap g rbTree".

The pattern matching checks are awesome - compiler will warn you if you wrote more general check before more specific one. The absence of this in C++ made my life a little bit more interesting than is comfortable for me.

In short, most of the time you can write code however you want or need and compiler will support you. As if you are "team programming" with a bunch of smart people - the compiler's authors.


👤 ModernMech
Something Haskell programmers commonly experience is that their programs typically work the first time they compile, due to the type system. I was skeptical of this but I've experienced it myself too -- it's kind of fun! What this means is that you spent most of your time thinking about how to express your code elegantly in the type system, but once you do it usually just works. That's a huge practical benefit you don't see in other languages without such an expressive type system.

👤 schwartzworld
It's a pure functional language. You can do functional programming in many languages, but Haskell enforces it by design. From what I've seen of the type system, it's quite nice as well.

Functional programming allows a great deal of confidence in your code,


👤 mark_l_watson
I like the separation between pure and impure code. In his Haskell class Eric Meijer said that pure code are like islands and monadic code is like the ocean, and as programmers we decide how much of a system is pure code.

Sorry for being off topic: the new M1 Macs seem to take some of the pain out of large runtimes for compile/build in languages like Haskell and Swift. I don’t have any benchmarks, this is just very noticeable when I am coding.


👤 banach
If we focus only on the benefits, her are two basic but distinguishing features that make it a very pleasant and productive language in my experience: - knowing through the type systems that a function’s result depends only on its parameters makes testing more reliable - the syntax and type inference makes it possible to write down many algorithms extremely tersely, which is also helpful in getting the implementation right

👤 alxmng
> Why would anyone choose Haskell to develop applications?

I chose Haskell to develop sumi.news because I enjoy programming in it, and because I don't want to worry about type errors and crashes at runtime.

> Does it offer any actual practical benefits over other languages?

Haskell offers a more expressive type system than other languages.


👤 youerbt
For your good old boring business software - ADTs and patter matching combo is, IMO, the most visible, practical benefit over "traditional" languages used in the industry. And something I miss the most when not writing in Haskell.

👤 georgewsinger
SimulaVR uses Haskell for its VR compositor: https://github.com/SimulaVR/Simula

There were some practical reasons for this, but at the end of the day: if you're going to spend thousands of hours developing something, you might as well choose a language that you find beautiful and enjoy working in.


👤 gjsman-1000
Because some people know it, like it, and because they can. It’s like asking why Facebook still uses PHP. But also, every language has something it’s particularly skilled at. There are still business applications out there in COBOL because there are some features hard to replicate in modern ones. No language ever dies.

👤 cauterize
I chose it due to the type system. Nearly every piece of data is optional. I need to compose these pieces of data to form a full set and apply that set of rules to a system. Haskell made a lot of things work out really well:

* embedded DSL for describing things with minimal syntax * types to enforce my invariants * immutable data + STM to protect my shared data structures * multithreaded/async code is easy to work with * deterministic outputs given inputs

but it was headaches in a lot of ways:

* exceptions - still not sure I’ve handled all exceptions gracefully * culture - most teammates are intimidated by Haskell (and types) * ecosystem is behind (Rust has exponential usb acceleration vs Haskell’s constant pace)

While I’m proud of the outcome I would have chosen differently now that I’ve seen the other side and have the project done. The inertia I was fighting required far too much energy


👤 blablabla123
I once used it for mathematical code in my thesis. Basically I had everything written with C++ code but it just didn't work. Also tried Matlab but I'm just not made to use it efficiently, so I tried Haskell for interfacing with the GNU GSL library. In the end I changed back to C++ but it helped me a great deal to understand what I was doing and to clean things up. Some nice features include obviously dealing only with constant expressions and being forced to write only mathematical transformations. A bit unexpected was that you can actually swap variable declarations, declaration order doesn't seem to matter much. Quite a big pain relieve when dealing with a lot of variables.

Actually ImplicitCAD is written in Haskell which implements CSG (very tricky to efficiently implement)


👤 vaibhavsagar
At my last job, we had a Python codebase that had grown large and unwieldy. We wanted a language with stronger compile-time guarantees and better concurrency support. After evaluating several options the team at the time settled on Haskell and it's still used on all our kiosks to perform tasks including interfacing with the credit card reader: https://www.youtube.com/watch?v=O-z8hDXIQSg

👤 engineerDave
A lot of this discussion has devolved into the management side of choosing a language and strayed from the realistic side. But insofar as to why people would choose Haskell...

Haskell is fast, compiled, type safe, memory optimized, allows concurrency and parallelism. The use cases where you'll see using Haskell will generally be companies like financial sector where very fast and error free execution directly translates to making more money, e.g. dark pool front running trading algorithms. Generally you don't hear it extolled because of who is using it and the secrecy around what it's being used for, e.g. competitive advantage.

Outside of that you'll probably only see it in academia because of a lot of the reasons listed in the replies. In my opinion its a harder language to learn because it really is just lambda calculus translated to a programming language.


👤 mbrodersen
Learning Haskell was a joy and it made me a better software developer. However I don’t reach for it when developing production software. The advantages doesn’t outweigh the disadvantages (compared with using more mainstream languages). I also highly recommend learning Agda/Idris/Coq/Lean/F*. They are to Haskell what Haskell is to mainstream languages. Learning them will make you a much better developer. Even if you never use them for production code.

👤 hardwaresofton
Haskell is the Mercedes Benz of modern PL. There are more advanced/esoteric languages, and there are less advanced/esoteric languages, but in general features developed, explored, and tinkered with in Haskell trickle down to other languages.

It offers less and less practical benefits over other languages because other languages evolve to where Haskell has been.

Haskell is correct, and it forces you to be correct and enforces a kind of clarity of thought that is seldom required from other languages. I think it's something you have to discover for yourself. If you don't see Typescript as strictly better than Javascript, you're probably not going to see the benefits of Haskell over any other language.

All that said, we have to ask ourselves which areas of computing Haskell can be profitably used in to gain the kind of critical mass that other languages have:

- Early programming, analysis, data science, etc -> Python is a better fit because it's easier to pick up, easier to understand, even though it's less correct. People discover libraries about checking types at runtime before they discover then can check them at compile time. Python has long since started it's evolution w/ the typing module.

- Web -> JS, because it's basically the only option. Projects like Elm and Purescript have made small dents, but the most successful cultural descendant of Haskell (if you can call it that) is Typescript.

- Startups -> Ruby/Rails, Django, NestJS, etc. win over Haskell here because you don't need to be right to have a successful startup, you need to find customers and after that product-market fit. Your startup could be airflow+google sheets with all-manual validation and still succeed over the most carefully crafted and bullet proof Haskell code.

- Safety critical systems -> Often are required to be realtime and it's easier to get to the safety requirements in other low level languages with strict procedure/process/standards and guaranteed realtime-capable OSes and tooling rather than using Haskell.

I've written about Haskell in the past (excuse the title):

https://vadosware.io/post/how-and-why-haskell-is-better/


👤 elviejo
Yes. On this study: A comparative study of programming languages in Rosetta code they show that Haskell programs are (brief) less lines of code to achieve the same goal.

Binary size is small..

And very important to me they could be executed even years after they were first uploaded to Rosetta code.

A very good study and the researches gave an entertaining talk on it, that I can't find now.


👤 ParetoOptimal
It's harder to write bugs and I only have to be smart in the beginning or at worst, on occasion.

👤 yakshaving_jgt
> Does it offer any actual practical benefits over other languages?

It sure does. Perhaps you should try it?