27 ms·
Ask HN: 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?
- schwartzworld 5y agoIt'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,
- amelius 5y agoNote, however, that you can still write a JavaScript interpreter in Haskell, and then shoot yourself in the foot by having side-effects.
- schwartzworld 5y agoSure. A program with no side effects can't do anything but warm up the computer
- blablabla123 5y agoI 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)
- gjsman-1000 5y agoBecause 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.
- la_fayette 5y agoPHP is amazing! Facebook uses Hack on HHVM.
- bliteben 5y agoI suspect PHP's popularity has really only waned in the US. Just my very anecdotal observations.
- banach 5y agoIf 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
- kadoban 5y agoThis also provides maintenance benefits. It's not _quite_ that if it compiles (after you make whatever change you wanted to) that it's correct, but it's not far off either.
- mooreds 5y ago> but it's not far off either. How "far "off" is it, in terms of correctness, compared to other, more conventional statically typed languages like C++ or Java or Rust?
- steeleduncan 5y agoSadly, there is not an obvious metric through which this can be answered, but the type system is much more advanced than that of C++ or Java, and as such you can be more precise about the inputs and outputs of a piece of code. As long as take advantage of the type system, the compiler tends to permit far fewer programs that compile, but do the wrong thing, than is the case in C++/Java. You will notice you spend more time editing code to make it compile, and less time debugging code that does compile. Rust should not be grouped with C++ or Java, as its type system is essentially that of Haskell with the addition of lifetimes. The developer experience is similar in that you tend to spend more time getting code to compile, and less time debugging.
- deleted 5y ago[deleted]
- tluyben2 5y agoIt 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.
- pengstrom 5y agoWhen 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.
- throwthere 5y agoJane Street has the same rationale.
- ntbdhalas 5y agoJane Street has big cult energy though you have to admit, if you've known anyone who worked there
- 7thaccount 5y agoI think it was more or less the best tool for the job (according to them) back when their tech lead chose it and now they've built all their tech stack around it. I remember a blog post or interview where he said they wouldn't necessarily use OCaml if starting again right now. I don't think he was referring to going the way of Haskell either.
- RapperWhoMadeIt 5y agoMaybe the same applies to building a RESTful API and choosing Go instead of js :)
- jpgvm 5y agoYou will get slightly better people but still the wrong people. JS is almost never the right tool for the job, Go is occasionally the right tool for the job, mainly if you need to write something that moves bytes from one fd to another without much in the way of business logic. TBH if you are building something boring you should just use Spring w/Java or Kotlin. This will attract pragmatists that ship code that works in ways that anyone else that works with these tools will instantly understand also. In a way it attracts mediocrity but in the good way where you get nice standard code that can be maintained cheaply for a long time and it's easy to hire for the skillset. If you are prototyping extremely quickly then maybe Ruby on Rails might be the right tool for the job (and thus attract the right kind of people). Go attracts mediocrity and not in a good way, it also actively repels the "right " people if you want to hire for highest intellectual horsepower for a given budget. In the same category as Haskell you also have OCaml, the Lisps (Clojure in particular) and Erlang all of which will yield you lots of the "right" people. None of these people will be cheap but none of the good people that write the other languages are cheap either, however there is a strong correlation between interest and proficiency in these languages and high intellectual horsepower - hence "right" in this context.
- ModernMech 5y agoSomething 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.
- deleted 5y ago[deleted]
- itronitron 5y agoThat aligns with my limited experience, that Haskell programmers seem to spend most of their time thinking about how to do something in Haskell.
- youerbt 5y agoFor 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.
- nunez 5y agoI haven't used pattern matching since I wrote F# and OCaml ten years ago and I still miss it. So, so expressive.
- hackerfromthefu 5y agoPattern matching has been added to various parts of C# these days.
- mark_l_watson 5y agoI 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.
- albedoa 5y agoIs this the class? https://www.edx.org/course/introduction-to-functional-programming https://www.edx.org/course/introduction-to-functional-progra... If not, can you share a link? Thanks!
- mark_l_watson 5y agothat is the class! I might take it again sometime.
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- yakshaving_jgt 5y ago> Does it offer any actual practical benefits over other languages? It sure does. Perhaps you should try it?
- atan2 5y agoSure, that would be the right approach I guess, but I think the whole point is trying to foresee benefits/problems before wasting time.
- yakshaving_jgt 5y agoI'm of the opinion that trying it out for yourself is not a waste of time. I'm sure several other commenters share that opinion, and I'm sure several others do not. The tone of the original question reads to me as though the asker is asking to be convinced by evangelists to give the technology a chance. Ultimately though, just listing technical benefits of the language is unlikely to be as effective as one might rationally expect, given that humans — which certainly includes programmers — are less rational than they would like to admit.
- sillysaurusx 5y agoYou’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=21 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.
- IceDane 5y agoWow. A whole 15 thousand lines of code, you say? Golly, that is just astonishing. What does the lines of code have to do with Haskell? Specifically, why did you feel this was important information? What you wrote is almost a non sequitur. That Haskell programmers are efficient and the fact that your port of a Haskell code base to python has reached 15KLOC are two completely orthogonal pieces of information. You probably didn't have to do it without running the program.
- hactually 5y ago[ smiles and nods ]
- deterministic 5y ago> monads are the Aristotle philosophy equivalent of programming. Take care not to study them too closely. Monads is just a pattern for composing functions that can’t be composed using “normal” function composition (because of incompatible types). That’s all it is. I never understood the fetishisation/worship of monads in the Haskell community.
- karmakurtisaani 5y ago
- elviejo 5y agoYes. 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.
- georgewsinger 5y agoSimulaVR uses Haskell for its VR compositor: https://github.com/SimulaVR/Simula 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.
- engineerDave 5y agoA 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.
- thesz 5y agoHaskell 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.
- omnibs 5y agoIt'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.
- cauterize 5y agoI 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
- vaibhavsagar 5y agoAt 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 https://www.youtube.com/watch?v=O-z8hDXIQSg
- mbrodersen 5y agoLearning 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 5y agoHaskell 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/ https://vadosware.io/post/how-and-why-haskell-is-better/
- alxmng 5y ago> 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.
- ParetoOptimal 5y agoIt's harder to write bugs and I only have to be smart in the beginning or at worst, on occasion.