Hacker News new | ask | show | jobs
by leoh 4391 days ago
Question: I've seen at least several succinct versions of programs written in Haskell. Would people say this is a benefit of Haskell? Just skill on behalf of the coder?
2 comments

One of the benefits of Haskell is indeed that this language makes it possible to write very expressive code. The same is true for other functional languages as well. However, this won't happen automatically. In other words, it will take some practice. You can certainly write convoluted code in Haskell.
Yes, one of the worst mistakes I've seen people make is trying to write Haskell exactly like you write code in other languages like Python.

If you ignore the power of Haskell's type system, and write all your code imperatively in the IO Monad, and continue to write large functions that do many things instead of writing smaller functions that can be composed, you gain almost nothing from Haskell, and you might have been better off writing your code in another language.

> you gain almost nothing from Haskell, and you might have been better off writing your code in another language.

Don't know about that. Even if you write everything in the IO monad, Haskell is still a pretty great imperative language and many people say it may possibly one of the best imperative languages ever written.

If you only use IO, then yes, you no longer gain the ability to reify and isolate effects as values but all the other strengths of Haskell's type system mostly remain invariant and just as useful.

I think it's a little bit of both. Yes, Haskell code is often quite terse, but the more important thing is that the type system allows abstraction to a much higher degree than in languages with weaker type systems. Abstraction always takes skill, but in Haskell usually once you come up with the abstractions, the type system allows you to (pretty easily and) safely use them.

    the type system allows abstraction to a much higher degree than in languages with weaker type systems
That may be true, but that's simply irrelevant in this case. The type system is not being used in [1] for any interesting searches (proofs, return type polymorphism, overload resolution, etc) here outside of the most trivial of polymorphic literals. Every standard library function in use here works practically identically in any functional language, including dynamic ones such as Clojure.

https://github.com/gregorulm/h2048/blob/master/h2048.hs