4 ms·
Engineering school: The costs and benefits for each problem must be analyzed and decided on a per-case basis. The cost of bring full, absolute perfection are a
by jerf 16y ago
Engineering school: The costs and benefits for each problem must be analyzed and decided on a per-case basis.
The cost of bring full, absolute perfection are absolutely staggering. One of the biggest ones that is easy to miss is that you rigidly limit yourself to current implementations; consider the case of writing your perfect specification in 1998, then spending a lot of time right now wishing a metaphorical half your 64-bit machine wasn't sitting there idle. The benefits of this absolute purity vs. what we already have right now? Pretty small next to the costs. But that's just one example.
Besides, fixing some of those all but requires a new hardware and OS platform. Floating point is intrinsically nasty from a mathematical point of view, but as long as it is what the hardware supports, it's going to have to be in your language, for instance, unless you just want to give up on numerical performance. Some of the os module nastiness is hard to actually kill without going not merely the full-on JVM-as-OS route but beyond, as even the JVM exposes some OS differences.
But I am serious about the case-by-case thing. There may be some things that are wrong and are worth being fixed. My previous paragraphs dismissed the idea of fixing the totality of the problem but that doesn't mean any given thing may not be an improvement.
- jhpriestley 16y agoIf your algorithm works on both 32-bit and 64-bit integers, then you can parameterize it: safeAdd :: (SmallInt i) => i -> i -> Maybe i safeAdd x y = if (maxBound - x) > y then Just (x + y) else Nothing `maxBound` would be a member of the `SmallInt` typeclass, with different values for `Int32, `Int64`, `Int23`, etc.
- aristidb 16y agoBounded is the typeclass you want.
- jhpriestley 16y agoAh, right. I don't actually do much numerically sensitive programming. Why aren't Haskell's SmallInt functions parameterized over Int size, anyway? Of the points brought up in the blog post, this one seems the easiest to fix.
- ezyang 16y agoIn many ways, this is where Haskell is as a language right now: we've compromised on many aspects because it was expedient to do so. But Haskell also has a reputation for pushing the envelope. Who knew you could get away with not allowing side-effects in arbitrary expressions? Who knew you could actually implement a lazy language, and actually have it perform quicker than interpreted languages? These are things that could have been decided on a case-by-case basis, but Haskell changed the rules of the game by asking you, on a case-by-case basis, to opt out of these features. In the real world, this has a very powerful influence on the library ecosystem. But I don't think I disagree with you. Just clarifying a point. :-)