4 ms·
While I agree that this error message sucks, I would like to point out that it could be improved greatly by adding a type annotation. Prelude> :{ Prelude|
by cole-k 5y ago
While I agree that this error message sucks, I would like to point out that it could be improved greatly by adding a type annotation.
Prelude> :{
Prelude| result :: Int
Prelude| result = 1 + [1,2]
Prelude| :}
<interactive>:3:10: error:
• Couldn't match expected type ‘Int’ with actual type ‘[a0]’
• In the expression: 1 + [1, 2]
In an equation for ‘result’: result = 1 + [1, 2]
Now I agree that this might not be an ideal thing to do when showing someone Haskell on a REPL, but I will argue in favor of annotating types at least for top-level declarations in a file. Especially for beginners, as learning to follow the types I feel is helpful to understanding the language and, in turn, its error messages.
I am told that well before I learned Haskell, type inference was the Cool Thing. However, I am of the opinion that a strong type system like Haskell's is best used with guidance (annotations) from the programmer. The more powerful your types, the better a specification you can write. And with a better specification, the type checker can give you better insight into what's wrong when it gets stuck.