4 ms·
Sure, the error that talks about FlexibleContexts could definitely be improved, but if you do enable that extension, then you get a much better error: • No i
by josephcsible 5y ago
Sure, the error that talks about FlexibleContexts could definitely be improved, but if you do enable that extension, then you get a much better error:
• No instance for (Num [Integer]) arising from a use of ‘it’
This one can be more straightforwardly understood to mean "you can't use a list of numbers as if it were a number". Also, starting in GHC 9.2, FlexibleContexts is enabled by default, so you'll get that better error the first time.
- bnchrch 5y agoBut their lies more problems for a beginner. What are extensions? How do I find out about them? Which should be enabled? Is my code broken because of me? Or because I should enable an extension? Anyway. It’s all not caring about beginners the whole way down when it comes to Haskell and it’s community
- xhevahir 5y agoThe funny thing is, when it comes to books and tutorials and such, there's way more material available at the beginner's level than at the intermediate or beyond. Seems like after a certain point you're expected to understand everything from looking at some type signatures.
- ParetoOptimal 5y agoWhen I learned Haskell long ago I remember being handheld to adding the correct extensions by the compiler. Very rarely do I remember being misled with valid code just missing extensions.
- josephcsible 5y agoWell to be fair, AllowAmbiguousTypes is kind of infamous for being suggested when it's not what you actually want.
- Iceland_jack 5y agoAnd `ScopedTypeVariables` is infamous for not being suggested
- lpghatguy 5y agoCompare this to the error message you get from Rust with the same program though: error[E0277]: cannot add `[{integer}; 2]` to `{integer}` --> src/main.rs:2:7 | 2 | 1 + [2, 3] | ^ no implementation for `{integer} + [{integer}; 2]` | = help: the trait `Add<[{integer}; 2]>` is not implemented for `{integer}` For more information about this error, try `rustc --explain E0277`. Good error messages are important for adoption of languages with strong type systems. The complexity is already foreign enough for people who aren't familiar with type theory.
- antonvs 5y agoRust is more constrained in ways that make type inference easier and less ambiguous. One issue mentioned in the OP is the way numeric literals are typed in Haskell. Haskell also has a lot of optional language extensions, some of them quite researchy, and that complicates type inference and error messages. It also has curried functions. These can all be fantastic things to have, but they involve tradeoffs. Those tradeoffs mostly make sense in the context of Haskell's original research focus. "Adoption" of the kind you're presumably referring to was an explicit non-goal for a long time, and still is among some users. Edit: sometime else pointed out that more recent Haskell compilers give the error "No instance for (Num [Integer]) arising from a use of `it'" for this example, so this whole post may be kinda BS.
- erk__ 5y agoOcaml does also not have a bad error message: $ ocaml OCaml version 4.13.1 # 1 + [2; 3];; Error: This expression has type 'a list but an expression was expected of type int Though it is also more constrained than Haskell here
- whakim 5y agoThat error's a bit better, but not much. You basically have to know that `+` only works on stuff that implements `Num` or else it still makes no sense. Compare that to the Rust/Python errors which are so much easier to understand.
- alisonkisk 5y ago