3 ms·
> the semantics of functional languages are vastly simpler than the semantics of your average imperative language. This is why C(++) is chock full of undefined
by dispose13432 10y ago
> the semantics of functional languages are vastly simpler than the semantics of your average imperative language. This is why C(++) is chock full of undefined behaviors, whereas a language like Haskell (built on extremely simple primitives like lambda-abstraction) have almost none
C(++) has undefined behavior because it's meant to run close to metal, and there's no official standard of CPU design.
If anything, a C compiler could always insert an "if" in a non-standard arch on every signed addition to get it to overflow the "right way".
The thing is that it would ruin performance.
And the proof is that Java, which was quite imperative, doesn't have nearly as much undefined behavior as C.
- wyager 10y ago> Java, which was quite imperative, doesn't have nearly as much undefined behavior as C. You're right, but Java is still orders of magnitude less predictable than Haskell. A few good links here. http://stackoverflow.com/questions/376338/what-are-the-common-undefined-behaviours-that-java-programmers-should-know-about http://stackoverflow.com/questions/376338/what-are-the-commo... It essentially boils down to a combination of unsound type systems and underspecified semantics. Java was not created on a sound theoretical basis - it's quite ad-hoc.