News for hackers. Stuff that matters.
Re:How to use Elm at work by phamilton on Tuesday July 12, 2016 @12:50AM (#12076810)
> you never get null pointers

To me, head [] is basically a null pointer.

Re:How to use Elm at work by dllthomas on Wednesday July 13, 2016 @04:35PM (#12089467)
To my mind, it differs importantly in that `head []` is something you basically can't inspect, and so you don't wind up passing it as something meaningful expecting the other side to check for it.

While I think this is an important difference, `head` is still harmful.

Re:How to use Elm at work by bbcbasic on Tuesday July 12, 2016 @05:38AM (#12077787)
You don't need to do head [] but nulls are unavoidable in Java.
Re:How to use Elm at work by tmptmp on Tuesday July 12, 2016 @08:17AM (#12078396)
How can I be sure that some lazy code (may be from some library) may not encounter "head []" at all?

Of course, I can avoid that by avoiding all such libraries.

Another painful thing is the exception handling is also not as clean and clear as, say Java/Python exception handling, AFAIK.

Please correct me if I am wrong here, and I will be a happy camper. In fact, I love Haskell as it has taught me how to think clearly. But I am scary to use it in production, sorry for that.

Re:How to use Elm at work by wyager on Tuesday July 12, 2016 @09:58AM (#12078952)
It's actually quite easy. Enable the completeness checker. It won't let you use head, because it's incomplete. In other words, it will say "stop using head".

What this entails practically is something like a) using safe head, which has type [a] -> Maybe a, or b) using the non-empty list type, or c) using streams, which don't have an empty constructor. There are lots of things you can do, but the general approach is "use pattern matching to cover all cases". The compiler can tell you if you've done this or not, and it you do your program will never crash.

>Another painful thing is the exception handling is also not as clean and clear as, say Java/Python exception handling, AFAIK.

Monadic exception handling is 100x easier than in Java or Python. Java copied Haskell/ML's use of Maybe/Optional for avoiding null pointers in Java 8, but they haven't yet figured out Haskell's use of Either and friends for exception handling.

Handling true exceptions in Haskell outside of IO code is worse than in Java, which is probably what you're thinking of, but most code bases completely avoid it. It's not hard at all. Handling true exceptions in IO is often nicer than Java, because Haskell has well-thought-out primitives like bracket.

Re:How to use Elm at work by tome on Tuesday July 12, 2016 @04:14PM (#12081986)
> Enable the completeness checker.

What's this "completeness checker"?

Re:How to use Elm at work by wyager on Tuesday July 12, 2016 @07:18PM (#12082892)
The -fwarn-incomplete-patterns ghc option.
Re:How to use Elm at work by dllthomas on Wednesday July 13, 2016 @04:30PM (#12089427)
That does not warn about using `head`. It wouldn't even warn about an attempt to define `head`, so long as you do so with a call to `undefined` or `error` (which is effectively what's done in the base libraries).
Re:How to use Elm at work by wyager on Wednesday July 13, 2016 @09:25PM (#12091098)
>That does not warn about using `head`.

You're right, I didn't realize that. Thankfully, `head` is one of the few common functions that's incomplete, and it's usually pretty obvious what they are.

> It wouldn't even warn about an attempt to define `head`, so long as you do so with a call to `undefined` or `error`

1. It's syntactically quite simple to avoid these two.

2. If you're using these, you're obviously aware your program can fail.

3. fdefer-typed-holes was introduced as a better alternative to undefined that warns you when used.

Re:How to use Elm at work by dllthomas on Wednesday July 13, 2016 @10:14PM (#12091260)
It's syntactically quite simple to avoid those two in your own code. You're not necessarily aware that a library you're using is using these.

That said, the community is pretty good at nudging people toward total functions, particularly in commonly used libraries (Prelude notwithstanding). And as you say, it helps that it is generally obvious when non-totality is newly introduced - infinite loops being the biggest exception, but that's unavoidable anywhere you don't have an actual totality checker.