Live data from Hacker News

Implementing 2048 in 90 lines of Haskell

gregorulm.com

1–10 of 25 posts

Re: Implementing 2048 in 90 lines of Haskell

#4
post #2

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?

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.

Re: Implementing 2048 in 90 lines of Haskell

#5
post #4
post #2

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?

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.

Re: Implementing 2048 in 90 lines of Haskell

#6
post #2

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?

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.

Re: Implementing 2048 in 90 lines of Haskell

#7
post #5
post #4

Earlier quoted context omitted.

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 be…

> 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.

Re: Implementing 2048 in 90 lines of Haskell

#9
post #8

This is neat and all, but the smooth animations of the original are probably not something you can easily pull off in few lines of code. And that is a very large fraction of the original, if I recall.

The smooth animations in Gabriele Cirulli's version are due to this API: https://developer.mozilla.org/en/docs/Web/API/window.request... They consist of a few lines of code.

Further, the animation code is only a miniscule fraction of that code base.

Re: Implementing 2048 in 90 lines of Haskell

#10
post #2

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?

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

Post reply on HN