3 ms·
Couldn’t the type system still allow using the + operator, but requiring the values on both sides to have the same type? You could do more magic like having int
by baddox 9y ago
Couldn’t the type system still allow using the + operator, but requiring the values on both sides to have the same type? You could do more magic like having int + float return a float, but I’d even prefer typing “int.toFloat + float” than “int +. float”.
- kbenson 9y agoYeah, that's what I was referring to by explicitly converting one operand so they are like types. I too would prefer this in a language that takes typing of this sort seriously.
- masklinn 9y ago> Couldn’t the type system still allow using the + operator, but requiring the values on both sides to have the same type? 'course it could, multiple languages already do that e.g. Rust (https://play.rust-lang.org/?gist=530fa94d3f451e896ac0d3ddeaf66ab1&version=stable https://play.rust-lang.org/?gist=530fa94d3f451e896ac0d3ddeaf...), Haskell (https://repl.it/repls/FrozenBlondUmbrellabird https://repl.it/repls/FrozenBlondUmbrellabird), Swift (https://repl.it/repls/LuckyNaiveBream https://repl.it/repls/LuckyNaiveBream)