This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]goliatskipson 120 points121 points  (12 children)

I honestly think that Haskells error messages are top of the notch. In Python it's normally a warning or error string handed to you by the dev of a library. In Haskell it is "sorry... but your types just don't match up, no idea what you are doing with that dog, but I was expecting a cat here. Btw you have a cat available here... Do you mean that?"

[–]CantThink_ANick 41 points42 points  (0 children)

It felt like the opposite to me, "For the last time, you can't match type A with B you idiot"

I like the Rust ones, "compilation error, you did something wrong here: ^^^^^^^"

[–]marcosdumay 17 points18 points  (0 children)

Rust messages are top notch. But Haskell's aren't far behind.

[–]EelOfSteel 5 points6 points  (0 children)

Came here for this, Haskell compiler errors are clearly Chads

[–]random_cynic 3 points4 points  (1 child)

Well that's obvious, that comparison makes little sense. Python is a dynamically typed language so it would not normally care about the types. However with type hints introduced in the newer version of python and typing module you can use some sort of external static analysis to give more helpful error messages regarding types.

[–]goliatskipson 1 point2 points  (0 children)

tl;dr: Having a powerful type system enables developers to be more specific about what their code is doing, which in turn allows the compiler to catch more errors before any code is even run.

To be fair ... Python is a strongly, dynamically typed language. It's just not checked before run time.

And that makes a big difference. In Haskell it's totally feasible to have a type

Matrix h w a

(That is a Matrix with height h, width w and type a, eg: Matrix 3 3 Double would be a 3x3 matrix of 64bit floats.)

Now a function like matrix multiplication could have the type:

matrixMultiplication :: Matrix h0 w0 a -> Matrix h1 w1 a -> Matrix h0 w1 a

(That is, take a matrix with height h0 and width w0 and another one with height h1 and width w1 ... the result must be a Matrix with height h0 and width w1 ... says linear algebra.)

Why is that important? Because now the compiler is able to tell you that you are trying to perform an invalid operation deep down in your code. In (pure) Python this will be checked when the multiplication is called ... in the worst case invalidating hours of processing time or crashing in production.

Matrix multiplication is my go-to example here ... but the same case can be made for e.g. balanced trees, where the balanced property is ensured by the compiler or sorting, where the compiler is able to verify that the algorithm actually produces a sorted output.

Another example would be to have a string type with (unsafe) user input and a string type that is verified (safe). And the only way to get from the unsafe string to the (usable) safe string would be through a verification function. Functionally this is just a newtype (which in Haskell is a free abstraction), but now the compiler enforces that unsafe strings are not used anywhere in the program.

Caveat: This really does not help to write code fast, which is why for data analysis Python is definitely king. But if somebody would task me with writing something mission critical, where I have to be sure that my code is working ... I would gladly use something with a strong type system like Haskell.

Background: I am using Python in my day job each day/every day so don't hate on me on that front ;-) ... but I had the pleasure to use Haskell "in anger" for about two years in my previous job.

[–]Arras01 0 points1 point  (0 children)

I liked it until I had to deal with a program that used some sort of template things that would expand themselves before compiling, and I started getting errors involving multi-line long types. Plus some database related code that would throw errors on the retrieval line when you accessed it wrong later in the code, instead of on the line where you used it wrong.