1. 11
  1.  

  2. 1

    It bothers me that Elm’s type system allows any of these to compile. I’ve never seen a language that strictly guarantees a lack of undefined behavior - even Haskell has runtime errors, and the ability to throw a runtime exception. I’d like to see someone write a language where it really is the case that all compiled programs are guaranteed not to crash, and any other behavior is a specification or implementation bug.

    1. 7

      First off, please don’t conflate runtime errors and undefined behavior. Errors in Haskell and most other languages are pretty well-defined in what they do.

      Wanting “guaranteed crash-free programs” is understandable, but the issue is they’re super tedious to write, and inevitably any program of size just has some variety of Result/Either threaded through that behaves like exceptions except with no stack trace. The other thing with the zero-exceptions ideal is it forces you to be defensive about things that need no defense. Example: regexes, like the article mentions. I shouldn’t have to write a runtime check to verify the compile-time condition of a correct regex. Same for indexing an array of known length: if I have code like let arr = [1, 2, 3] Just first = arr !! 0 in first the compiler should not force me to provide an exhaustive match on arr !! 0.

      Also note that even in Elm’s limited case, errorlessness forces them into some really questionable design decisions. For example, what’s n / 0? Well, for floats it’s infinity (fine) but for ints it’s 0 (super not fine!) Of course they did this because it would be incredibly tedious to have to unpack a Maybe for each integer division. I would rather have my program crash than be subtly broken by this silliness.

      1. 0

        In actuality, how often have you used n / 0 to actually crash the program and appreciated it? You can consider division by 0 to be a logic error - and therefore, it’s something that should be caught by tests, not by the compiler.

        1. 1

          Would be great if someone replied instead of just downvoting. One thing I like lobsters is that people don’t downvote just because they disagree, and instead comment to further the understand of the community.

      2. 1

        That is the case with Elm. All the the things I’m talking about here are implementation bugs, except for the single case of Debug.crash. It’s actually nice to be able to rely on your frontend code. With Elm, if my code compiles, it works. I don’t have to worry about it crashing at runtime – and that’s not something to turn your nose at.