6 ms·
What would be the reason to learn Rust over Haskell? They seem to be about in the same speed ballpark: http://benchmarksgame.alioth.debian.org/u64q/compare.ph
by jonahx 12y ago
What would be the reason to learn Rust over Haskell? They seem to be about in the same speed ballpark:
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=ghc&lang2=rust http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...
Is that not representative, or is the idea that Rust speeds the learning curve with its similarity to Ruby?
- Jweb_Guru 12y ago(1) Even in that benchmark, Haskell is over twice as slow as Rust on average. (2) The Haskell code is nowhere near idiomatic. It is still useful to know that Haskell can be quite fast if necessary, but it likely does not reflect what your actual experience using Haskell would be.
- codygman 12y ago> (2) The Haskell code is nowhere near idiomatic This isn't meant as a personal attack firstly. Secondly, I've heard this said more than a few times lately and am generally curious: Do you know which Haskell examples are idiomatic, which aren't, and why? I feel like in the case of some it's just parroting someone elses argument.
- jakevn 12y agoA glance at the source quickly reveals an unsafe implementation.
- codygman 12y agoI didn't see an import for unsafe or foreign in: fannkuch-redux pidigits binary-trees
- jakevn 12y agofannkuch-redux heavily utilizes unsafe operations on a mutable vector. binary-trees uses artificial strictness for the sake of the benchmark. Nine of the ten Haskell implementations are demonstrations of writing C in Haskell (without reaching C's performance).
- imanaccount247 12y ago>fannkuch-redux heavily utilizes unsafe operations on a mutable vector. They are just not bounds checked. That is not "writing C in Haskell". >binary-trees uses artificial strictness for the sake of the benchmark What on earth is "artificial strictness"? Forcing evaluation when you need something to be evaluated immediately is not artificial, not unidiomatic, and not "writing C in Haskell". >Nine of the ten Haskell implementations are demonstrations of writing C in Haskell And end up shorter than rust? The idea that writing lower level code is "writing C in haskell" is nonsense, the ability to write more verbose but faster code is not harmful, it is useful. But the fact that lower level haskell is still shorter than rust and yet you want to act like it is some sort of horrible thing makes it hard to believe that you are really concerned about the horrors of writing slightly more verbose code.
- jakevn 12y agoThe Rust code is both safer and faster at the cost of more keystrokes. I'm not certain the point of writing unsafe code in Haskell when there are better tools for the job. Haskell is fast enough as is and using it to hammer screws just reeks of wrong tool for the job.
- imanaccount247 12y agoYour comment says absolutely nothing, and that appears to be the goal. What is the point of writing any code in any language? It is a benchmark, the point of it is to write the fastest code you can. You aren't obligated to write lower level code in haskell, nobody has a gun to your head. So why do you pretend it is a problem, and claim other languages are "better tools" for that job despite haskell clearly being very good at that job?
- Jweb_Guru 12y agoJust in the first two examples on that page, you'll find allocaArray, mallocByteString, writeAlu, unsafeUseAsCString, unsafeIndex, withForeignPtr, unsafeDrop, and more. You really don't have to know Haskell very well (and I'm not claiming to be an expert by any stretch) to understand that this is far from idiomatic in a lazily evaluated, pure functional language. No parroting required.
- imanaccount247 12y agoYou should know it at least a tiny bit though, or else you lump perfectly "idiomatic" functions in with low level functions that aren't often used and pretend they're a problem. How is a indexing an array without a bounds check somehow counter to lazy evaluation or functional programming? It is the exact same thing as indexing it normally, just without checking the length.
- bjz_ 12y agoThe point is that is unsafe. You don't need to do that in idiomatic Rust code, because the bounds-check-free indexing is encapsulated inside the iterator library. So to re-frame it: fast, idiomatic Rust code is safer and easier to write than fast, idiomatic Haskell code.
- imanaccount247 12y ago>The point is that is unsafe No, the point was that it is "far from idiomatic". Did you read the post I was replying to?
- coldtea 12y agoHow is indexing an array OK with functional programming of the level of purity Haskell strives for (not to mention without bounds checking)? In "Real World Haskell" they advise you to forgo of arrays, and even has a chapter "Life without arrays", saying "arrays and hash tables are often used as collections indexed by key, and in Haskell we use trees for that purpose".
- imanaccount247 12y ago>I feel like in the case of some it's just parroting someone elses argument. It usually is. The reality is that like most memes like this, there's a grain of truth at the center, but most of the people repeating it don't know where the truth ends and the exaggeration begins. Regex-dna is using low level ByteString operations to squeeze out a bit of extra performance. This makes it quite a bit longer and would rarely be done in practice since the gain is small. Fasta again does some low level ByteString operations, but not nearly as significant as regex-dna. Not that bad. Others like fannkuch-redux are just using "unsafe" vector functions. All that is doing is leaving out bounds checks. That makes an miniscule difference in performance most of the time, but the way the shootout works there's only incentive to completely optimize for speed, so you get 1% optimizations you wouldn't normally see. I'd hardly call it unidiomatic though, you just normally use "read" instead of "unsafeRead", etc. In some cases I would say the unsafe calls are idiomatic. If you are going to be doing an operation repeatedly in a loop, doing the bounds checking once before looping and using the non-bounds checked calls in the loop is pretty standard. Pidigits is normal haskell (although you could argue the lack of spacing isn't idiomatic, but that hardly matters). I stopped there since the rest are getting enough slower than rust, but looking them over there's still nothing outrageous, just more low level ByteString usage. Overall none of them are that far from idiomatic, none of them do anything particularly crazy, and I think the speed gains from doing most of the optimizations they are doing are fairly small. I find it particularly odd that people act like the ability to write lower level code that is faster is a problem with haskell. Especially given that the "low level" haskell versions are often still shorter and no harder to read than the "idiomatic" rust versions.
- bjz_ 12y agoOk, so perhaps I grant you the fact that unsafe indexing is idiomatic. The Rust code is still safer and more robust against buffer overflows in the long term. Also, isn't regex-dna using libpcre? That's a C library, no? Rust's regex library is pure Rust, with no unsafe code. I love Haskell, but I still don't think it occupies the same space as Rust.
- codygman 12y ago
- coldtea 12y ago>Do you know which Haskell examples are idiomatic, which aren't, and why? Why wouldn't he? With a little familiarity with programming at large and Haskell syntax can learn to discern the two cases even if you're not a Haskell programmer.
- wycats 12y agoIdiomatic, typical Rust code does not involve a garbage collector, which makes it suitable for embedding in environments with a garbage collector as well as any application with real-time (no pauses) requirements.
- bjz_ 12y agoIf you actually look at the source code, the benchmarks where Haskell beats Rust rely on unsafe functionality, calling out to C libraries, and are heavily optimised and hard to follow. The Rust code on the other hand is idiomatic, safe, and relatively easy to understand.
- deleted 12y ago[deleted]