News for hackers. Stuff that matters.
Re:What I Wish I Knew When Learning Haskell 2.0 by thinkpad20 on Wednesday April 23, 2014 @07:50PM (#7637686)
As to Haskell's syntax, I think it's really just as complicated as it needs to be to express the ideas Haskell embodies succinctly and precisely. It doesn't have any more syntax than most other languages; it's just a very different syntax than most non-functional languages. And this is precisely because the semantics of the language are also very different. Haskell, for example, is not block-structured, as nearly all imperative languages are. (It does simulate this with do-syntax, but this is only a simulation). I understand though - I find Clojure practically unreadable, and this has kept me away from it to a degree.

As to where Haskell fits: you're correct, there are many other great languages out there. But I think Haskell is really unique in offering what it does. Clojure, Go, and Erlang are all great in their own regard, but none of them provides the degree of safety that Haskell does. For example, none of them enforce purity, and all three of them freely allow the use of `null` values (which is really quite surprising considering how many problems nulls cause). Clojure and Erlang avoid mutable state like Haskell does (though not to the same degree of rigor) but don't provide the elegant solutions for simulating mutable state that Haskell does with its monads, which almost allow you to "have your cake and eat it too" with state. None of them encourage the degree of abstraction that you'll find in Haskell. Also, at least according to the Computer Benchmark game, Haskell beats all three of them in terms of speed, as well. Haskell's "place" is in generating highly robust code with good performance, and also works as a beautiful language for expressing certain mathematical concepts.

This doesn't make Haskell a perfect language, but it absolutely has a lot to offer that other languages don't. And it's so much different than other languages, that at the very least it can change your perspective on a lot of things.

Re:What I Wish I Knew When Learning Haskell 2.0 by platz on Wednesday April 23, 2014 @08:16PM (#7637805)
I think one has to be careful about performance claims.

Of course you can tweak things to be fast in hakell, but to be able to actually program haskell in such a way to, beat other languages in performance, is not a trivial skill.

There are numerous stackoverflow and r/haskell posts "Why is my haskell code 10x times slower than language X?" Or observe this set of web framework benchmarks: http://www.techempower.com/benchmarks/

Re:What I Wish I Knew When Learning Haskell 2.0 by chongli on Wednesday April 23, 2014 @11:16PM (#7638325)
Of course you can tweak things to be fast in hakell, but to be able to actually program haskell in such a way to, beat other languages in performance, is not a trivial skill.

It actually is trivial in a lot of cases. It's often as simple as swapping out lists for vectors and inserting a few strictness annotations into your types.

Re:What I Wish I Knew When Learning Haskell 2.0 by danieldk on Thursday April 24, 2014 @03:39AM (#7638913)
...and using the ST monad. In the end it pretty much ends up looking like an imperative program.

The good news is that it stops at the function boundaries. Your quicksort may be implemented in the ST monad, looking like some bastard child of C, but the function type ends up being

  qsort :: Ord a => Vector a -> Vector a
And that's one of the likeable properties of Haskell: it doesn't deny that real-world programs sometimes require mutability, but allow you to isolate it through the type system. So, even though qsort may use mutable memory for sorting, it is a pure and referentially transparent function.
Re:What I Wish I Knew When Learning Haskell 2.0 by thinkpad20 on Wednesday April 23, 2014 @10:24PM (#7638185)
That good performance is not trivial to achieve is not really here nor there. Haskell is a difficult language and many people come into it with assumptions that come from imperative or strict languages and don't hold up in a lazy functional language. That there are programmers who are using the language in a non-optimal way, and coming away with reduced performance, is not a mark against the language itself. To the extent that the benchmarks prove anything, they prove that you can write Haskell code to be competitive with or any other language, at least in regards to those specific problems. Of course, it certainly doesn't prove that there are no areas in which Haskell - as a language, not in regards to specific uses - is not in the upper level of performance. As to the web frameworks benchmarks, I can't speak to them, as I don't know whether they were written expertly or with the latest available libraries. Maybe they aren't as fast. Regardless, it's clear that it's more than possible to write very performant code in Haskell, so ruling it out on those grounds makes little sense.
Re:What I Wish I Knew When Learning Haskell 2.0 by platz on Wednesday April 23, 2014 @11:42PM (#7638385)
I don't think I made a mark against the language itself, or tried to rule it out, or tried to indicate it cannot attain the highest levels of performance -

Yes, my point was just that there are programmers using Haskell in a non-optimal way. Beginners seem to be surprised when their Haskell code isn't automatically in the upper level.

I'm not really a great fan of benchmarks, or this particular benchmark, but at least the source of every test is available:

https://github.com/TechEmpower/FrameworkBenchmarks/blob/mast...

https://github.com/TechEmpower/FrameworkBenchmarks/blob/mast...

https://github.com/TechEmpower/FrameworkBenchmarks/blob/mast...

Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Thursday April 24, 2014 @01:08PM (#7641528)
> at least the source of every test is available

Also true of the benchmarks game. (Also the command line used to compile and run the program, etc)

Re:What I Wish I Knew When Learning Haskell 2.0 by platz on Thursday April 24, 2014 @02:16PM (#7641914)
Except the code used in the benchmarks game is hardly idiomatic
Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Thursday April 24, 2014 @02:41PM (#7642070)
According to who's idea of what is or isn't idiomatic? Yours? Don Stewart's?

http://www.willamette.edu/~fruehr/haskell/evolution.html

Is this "idiomatic": http://benchmarksgame.alioth.debian.org/u64q/program.php?tes...

"One can, with sufficient effort, essentially write C code in Haskell using various unsafe primitives. We would argue that this is not true to the spirit and goals of Haskell, and we have attempted in this paper to remain within the space of “reasonably idiomatic” Haskell. However, we have made abundant use of strictness annotations, explicit strictness, and unboxed vectors. We have, more controversially perhaps, used unsafe array subscripting in places. Are our choices reasonable?"

"Measuring the Haskell Gap" http://www.leafpetersen.com/leaf/publications/ifl2013/haskel...

Re:What I Wish I Knew When Learning Haskell 2.0 by platz on Thursday April 24, 2014 @02:56PM (#7642176)
The meteor example isn't bad at all, no.
Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Thursday April 24, 2014 @03:15PM (#7642282)
Re:What I Wish I Knew When Learning Haskell 2.0 by lomnakkus on Friday April 25, 2014 @01:27AM (#7644901)
No, that's not idiomatic Haskell code for an application. Foreign.Ptr (and companions) are hardly ever used in normal Haskell code unless you're optimizing for that last bit of performance -- and even then I'd be very hesitant about using it because of the lack of bounds checking, etc.

FWIW, I don't Don Stewart[0] would consider that idiomatic either. He just knows a bit more than the rest of us about how to squeeze more performance out of GHC-compiled code and was willing to use non-idiomatic code to do so.

Also FWIW, personally I don't think language shootouts are very informative most of the time, but... IMO they should at least use idiomatic code -- otherwise they tell you even less than they already do about what real-life performance is like.

[0] Just an example, I know he didn't contribute the particular benchmark you linked to. He did contribute a few of the other programs AFAIK. I think the following sentences also apply to (essentially) all the Haskell shootout contributors.

Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Friday April 25, 2014 @12:33PM (#7647496)
>I know he didn't contribute the particular benchmark<

This otoh: http://benchmarksgame.alioth.debian.org/u64q/program.php?tes...

>Foreign.Ptr (and companions) are hardly ever used in normal Haskell code unless you're optimizing for that last bit of performance<

Do you think "optimizing for that last bit of performance" doesn't happen in the wild?

>IMO they should at least use idiomatic code<

Provide some!

http://benchmarksgame.alioth.debian.org/play.php#contribute

GHC 7.8.2 installed, cabal 1.2 stuff available as-needed.

Re:What I Wish I Knew When Learning Haskell 2.0 by lomnakkus on Friday April 25, 2014 @02:14PM (#7648155)
> Do you think "optimizing for that last bit of performance" doesn't happen in the wild?

Of course it does, but the cost increases non-linearly and you have to find the right trade-off for the situation at hand. Do you want maintainability or absolute performance?

> Provide some!

Of course one could, but that would that accomplish? Everyone who thinks these benchmarks have value just looks at the fastest-performing version of $YOUR_LANG_BENCHMARK. Hint: Mostly it won't be idiomatic regardless of the value of $YOUR_LANG.

Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Friday April 25, 2014 @02:52PM (#7648376)
>but the cost increases non-linearly<

Do you think the source code for those optimized for the last bit of performance programs tells us something about that?

>Of course one could, but what would that accomplish?<

Could one? Perhaps there'd be complaints that your "idiomatic programs" were just naïve.

A passive website like the benchmarks game can never be enough, by itself, to educate and inform all (or even most) readers -- reading selectively is far too commonplace and errare humanum est.

The benchmarks game is a resource. There are enough examples that when someone draws a misinformed conclusion, we can usually show them a counter-example and ask them to think.

But only if someone contributes those (whatever they consider idiomatic to be) idiomatic programs as counter-examples.

Re:What I Wish I Knew When Learning Haskell 2.0 by username223 on Wednesday April 23, 2014 @10:24PM (#7638186)
> Of course you can tweak things to be fast in hakell, but to be able to actually program haskell in such a way to, beat other languages in performance, is not a trivial skill.

No kidding:

    http://benchmarksgame.alioth.debian.org/u64/program.php?test=regexdna&lang=ghc&id=2
It's mostly a matter of knowing C, then knowing how to torture GHC into doing what the C would do.
Re:What I Wish I Knew When Learning Haskell 2.0 by copergi on Wednesday April 23, 2014 @11:24PM (#7638336)
Linking to the benchmark game as if it means something should be a bannable offense. When you look at something that encourages speed at all costs, that is what you will see. People do low level optimizations like that to gain 0.5% better performance. That does not mean you need to do anything like that to get good performance.
Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Thursday April 24, 2014 @01:22PM (#7641603)
> That does not mean you need to do anything like that to get good performance.

Please contribute your Haskell regex-dna program that does not do anything like that and get's "good" performance.

Here's the task description: http://benchmarksgame.alioth.debian.org/u64/performance.php?...

Here's "How to contribute programs": http://benchmarksgame.alioth.debian.org/play.php#contribute

GHC 7.8.2 installed, cabal 1.2 stuff available as-needed.

Re:What I Wish I Knew When Learning Haskell 2.0 by copergi on Thursday April 24, 2014 @02:12PM (#7641877)
>Please contribute your Haskell regex-dna program

No. I stopped bothering with that cluster fuck like a decade ago. It is a complete waste of time.

Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Thursday April 24, 2014 @02:43PM (#7642085)
We can stop bothering about your -- "That does not mean you need to do anything like that to get good performance."
Re:What I Wish I Knew When Learning Haskell 2.0 by copergi on Thursday April 24, 2014 @06:42PM (#7643574)
You can do whatever you want. But drawing nonsense conclusions won't suddenly become reasonable just because you are defensive about the shootout.
Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Friday April 25, 2014 @11:51AM (#7647222)
My conclusion is that you've made a claim and done nothing to support that claim.
Re:What I Wish I Knew When Learning Haskell 2.0 by igouy on Thursday April 24, 2014 @01:11PM (#7641542)
According to the benchmarks game, one has to be careful about performance claims :-)

http://benchmarksgame.alioth.debian.org/dont-jump-to-conclus...