+22

What can you achieve with the Haskell language that you can't achieve with a more commonly used language like Python or Java?

I guess I am after the specific benefits of Haskell in addition to the general benefits of functional. Are there any real world applications that warrant it's use? Is it purely for the theoretical types and mathematicians who are impressed by its purity or are there concrete applications that make it outperform Python, Java or other languages? Does it have applications in say optimisation? I've searched here for a similar question but couldn't find a direct match apart from requests to add Haskell to the list of languages taught.

3/19/2019 4:14:04 AM

Sonic

10 Answers

New Answer

+16

Was still asleep sorry :P One thing Haskell has going for it is that all the code has no side effects ("purity"). You cannot simply print things to the console from anywhere for example without explicitly declaring that your function does I/O. This might sound restrictive but it works in practice and it means the compiler can do optimizations it couldn't otherwise (memoization!). Also, this means you can trivially run any Haskell code in multiple threads at once without having to worry about deadlocks etc. No side effects = No problems. Also Haskell is lazy, it only computes what is necessary. You will commonly write down infinitely long lists in Haskell, but if you never request more than 20 items from one, they'll never be computed. There's also stuff like stream fusion but I'm already running out of space. Lots of concepts from Haskell have found their way into other languages, most prominently monads (js Promises for example), and languages on average have become a lot more functional lately!

+10

I have found that it's harder to write super performant Haskell though, it's easy to shoot yourself in the foot without noticing, performance-wise. But you can certainly do it if you're willing to lose a bit of the elegance and terseness on the language. (You have to force non-lazy evaluation, rewrite stuff already in the standard lib, etc.) That being said most code performs fine without going to crazy about optimization.

+7

Haskell =functional Functional =everything is function Oop=everything is object Ok, functional has benefits... But there is a big BUT. Once functional, always functional. If you choose this way its hard to turn back to oop but if you choose oop you can use functions too. I want to try soon one functional language like haskell or clojure. You can do great things.

+5

Schindlabua ?

+5

Aside from the benefits of functional (safety, correctness, etc.), there is one thing Haskell has which sets it apart from languages like OCaml. The compiler is absolutely incredible. If you write good code, you can get half the performance of a C program. Half! That's incredible! And that's with one of the highest-level languages available, that also has a garbage colector. For reference, Go, a fast, garbage collected language, is 1/10th the speed of C and Python is 1/100th. But aside from that, no, it's not very practical, which is why it isn't used much outside academia.

+5

Schindlabua's answer was excellent. Vlad's answer was also very good. Maybe to add more on the real-world application part, I'll try to offer some idea of breadth. We have a local Haskell Meetup that showcases their software. I haven't attended in awhile, but I remember one member was working on some sort of music composition software. There are a handful of "Haskell shops" in the US. Since they are both our (the company that I work for) competition and our colleagues, I won't mention them by name, but we get some clients from them every now and again. From that, we gauge that there is a very wide variety of industries that use Haskell in their software. Actually, FaceBook uses Haskell for some of their software (you can look it up). We primarily use Haskell for building domain-specific languages and fast trading robots. The more Haskell is used in paid projects, the better the tooling will become, which may encourage further adoption.

+4

I started learning Clojure recently, which is also a functional language, based on Lisp, with Java interoperability. It is awesome in so many ways, opens up new worlds, new ways of thinking. There are no variables, only immutable data and powerful transformations. You start to appreciate recursion and realize that almost everything can be expressed with filter, map and reduce. :) Of course I exaggarate but my Clojure journey has just started and I enjoy it immensely. Also I want to learn Haskell too. I believe that functional programming requires a mindset to tackle problems, which you cannot acquire from fashionable languages like java or js. And once you learn it, you can apply it elsewhere and will make you more productive.

+1

safety of function correctness and very good compiler

0

what is the answer to the double quote

0