3 ms·
This isn't about coercion, which Haskell doesn't have. These error messages arise because of Haskell's choice that numeric literals should be polymorphic values
by momentoftop 7y ago
This isn't about coercion, which Haskell doesn't have. These error messages arise because of Haskell's choice that numeric literals should be polymorphic values with a typeclass constraint, meaning I can make those literals evaluate to my own types by defining a few instances. The resultant headaches with error messages are just the usual ones you get when you combine this amount of ad-hoc polymorphism with global type inference.
For teaching beginners, I very much question the amount of polymorphism in Haskell, and one floated idea has been to use a custom Prelude with much less of it for teaching purposes. Alternatively, I would probably just tell students to read an error like that as "you did something wrong." I would say the same for any student faced with a Java stack-trace showing how their null value threw an exception deep inside library code.
- Quekid5 7y ago> meaning I can make those literals evaluate to my own types by defining a few instances. If you're defining instances, you're already an "expert", so why are you defining instances that are "hostile" to your beginner students? If people in the ecosystem are defining hostile instances, you should probably just ask them to stop it...? EDIT: Also, isn't failing to compile the almost-optimal case? It certainly doesn't fail at runtime.
- momentoftop 7y agoThe beginner isn't defining the instances. But the experts want the flexibility to define such instances, and that means even beginner code can involve an unhelpful amount of polymorphism. This isn't the case in Rust, where literals are near enough monomorphic. There's a similar situation with the now classic: Prelude> length ['a','b'] 2 Prelude> length ('a','b') 1 Here, beginners are potentially being burned by the fact that "length" is polymorphic with the type: length :: Foldable f => f a -> Int which is not a type I want to explain to beginners. At the same time, as an expert, I want length to be polymorphic and don't want to sacrifice its polymorphism for the sake of beginners.
- Quekid5 7y agoI don't think that's an example of what was being talked about, but... I appreciate the issue. I think I've even been bitten by this once! I think the problem there is really calling it 'length'.