Live data from Hacker News

Destroying C with 20 lines of Haskell: wc

0xd34df00d.me

71–74 of 74 posts

Re: Destroying C with 20 lines of Haskell: wc

#71
post #69

Earlier quoted context omitted.

Could you elaborate on how you read the wc code? I ask because the essay and your comments until now show no insight from reading the code. I find it difficult to understand how anyone could miss that (rather significant) part of the core algorithm, and then assert the differences are due to only "modulo intended Unicode space handling" and the like. Until now I had assumed you had a lay understanding of wc, and had…

I was mostly curious about how wc handles spaces and whether ignoring non-ascii spaces brings me closer or farther from what wc does. So I focused on that, and this specific printable characters handling didn't caught my eye. On a meta level, I wasn't even considering that the notion of a word might be different from "a sequence of characters that aren't space characters". Live and learn indeed.

Thank you for the clarification.

Re: Destroying C with 20 lines of Haskell: wc

#72

Earlier quoted context omitted.

Thanks for replying. I want to tell you that I feel deep regret for my impulse to publically shame you - even though I've gotten a lot of points for this comment, and did not really receive criticism for it. Hey - if you make performance optimizations and compare implementations, it's probably best not to jump to quick conclusions. I would advise to brush up on C to get a feel for performance. Or, in times where it's…

No worries, that's a natural reaction! > In practice it's unlikely that you find yourself in a situation where you can write code in a high-level language that runs considerably faster than what you could realistically write in C. I do way more C++ (in fact, I don't do pure C at all), and aliasing has bitten me and my code performance more often than I'd like. While there are workarounds, I'd probably consider spendi…

[deleted]

Re: Destroying C with 20 lines of Haskell: wc

#73

> So we’ve managed to just smash a C program that was looked at by thousands of eyes of quite hardcore low-level Unix hackers over a few decades. We did this with a handful of lines of pure, mutation-less, idiomatic Haskell, achieving about 4 to 5 times of throughput of the C version and spending less than an hour on all the optimizations. I've done many very arrogant things in my life, because I've been a strange gu…

It would be great if your post added value in the discussion.

Re: Destroying C with 20 lines of Haskell: wc

#74
post #65

Earlier quoted context omitted.

The github repo description is equally distasteful too: > wc implemented in Haskell (significantly faster than GNU coreutils version — oops I did it again For reference, I'm referring to the "oops I did it again" part. It's really hard to take that comment as "honours go to GHC authors". Also, I suggest you try running the GNU wc with unicode turned off because unicode is computationally expensive and you're delibera…

> For reference, I'm referring to the "oops I did it again" part. It's really hard to take that comment as "honours go to GHC authors". Was overly excited when I created the repo after obtaining the first results. Childish indeed, thanks for reminding, fixed. > Also, I suggest you try running the GNU wc with unicode turned off because unicode is computationally expensive and you're deliberately disabling unicode supp…

wc running slower seems wrong. I wonder if it's doing additional sanitising because your LANG differs from your LC_ALL. I'd need to read through the code to get a handle on what it does and doesn't expect though but I definitely wouldn't expect wc to run slower.
Post reply on HN