4 ms·
You can do that. But as a language feature, inter-procedural inference creates problems for humans. There's no way for humans to see what type a function wants.
by Animats 2y ago
You can do that. But as a language feature, inter-procedural inference creates problems for humans. There's no way for humans to see what type a function wants.
Language design seems to be converging on the idea that functions should have human-readable type signatures, but within functions, automatic inference can be used freely. In one direction, we have the "auto" inference mechanism of C and C++,
and the local inference of Go and Rust. In the other direction, we have TypeScript for JavaScript and Python's rather strange unchecked optional typing. All those changes move towards the center position.
(Then, of course, there are "lambdas", but that's another subject.)
- js8 2y agoWell, it kinda works in Haskell, but you get weird type signatures. I haven't tried Liquid Haskell but it looks like a potential solution. But you're right. Even in Haskell, I always write type signatures for functions. It makes type inference debugging easier. But as I understand it, this feature in Ruby is for compilers. It's a compiler's job to translate human-readable (hopefully) source code to an efficient mess of machine code.