4 ms·
A type check would give map a type, say [a] -> (int -> a -> b) -> [b]. If you try to apply it to any function that does not have the type (int -> a -> b), the c
by choeger 6y ago
A type check would give map a type, say [a] -> (int -> a -> b) -> [b]. If you try to apply it to any function that does not have the type (int -> a -> b), the check would fail.
- username90 6y agoSo basically any language that does any form of type checking at all.
- MaxBarraclough 6y agoNot including TypeScript.
- xsmasher 6y agoJust to clarify, if you update toReadableNumber to take a second parameter and that parameter is not a number, typescript will complain.* TypeScript won't catch the original landmine because it ignores the extra parameters; maybe some linter would? Is there a rule that enforces "functions used by map must spell out all the parameters?" * Example of typescript giving an error on toReadableNumber_v2: https://www.typescriptlang.org/play?#code/FAYw9gdgzgLgBAQwE5IQTzgXjgbQIwA0ATAQMwC6A3MDQGYCuEIMAlpHDGAEoCmCAJggBGAGx4A5egFshPJAAoI0gFxKZcgJQBvYHD1wkPGPSQQ4agHScAYiwAePfvKIbqAXxrAGTVu068BYTFJdSQAfQA3IkUVNVkkAjgAB0Nae2VYJBYIAHNtXX1DY1Nk1Ps4AGpzaSswWwcnF3cacGgwMQsRMBz5RBR0CykEJN7-PkFRCWl4uA1Z6hbIKHaeTu7e5FQ0QeHR7nGgqdDIoln5miA https://www.typescriptlang.org/play?#code/FAYw9gdgzgLgBAQwE5...
- wruza 6y agoSee also magicalhippo’s comment on overloading. We could introduce real types instead of primitives, so that ‘number_formatting_base_t’ would conflict with ‘array_index_t’, but nobody in the world bothers beyond bare ‘int’.
- kuschku 6y agoActually, that's what I use inline types in kotlin for. So username, password are distinct from string and objectid might be backed by an int, but is distinct from int. Obviously, once compiled, there's no overhead, it's a zero cost abstraction. But an incredibly useful one.
- username90 6y agoYeah, I see the point, in for example C# if you have overloaded methods it tries it best to map it to the accepted type. However you'd have to work really hard to invent a case where a library updates a signature to accept another type, and then you in your code have 2 overloads of a method that you pass and it now choses the wrong version, all while the library change doesn't break any other code. Scenario: Library changes signature so you always pass functions with more parameters. Result: This will break almost every codebase, they probably wouldn't do this in a minor patch. Scenario: Library adds a new signature where you can pass functions with more parameters and keep them overloaded between each other. Result: Compiler can't identify which of the two signatures to pass your overloaded function and throws a compilation error.
- Akronymus 6y agoOn my personal projects with F#, never got a chance to use it professionally, I actually use them. Makes modeling the data much easier.