5 ms·
I was confused by this, too. It feels like the target audience for this post must be people coming from dynamic-typed, late-bound languages? Hence the reference
by cmrdporcupine 4y ago
I was confused by this, too. It feels like the target audience for this post must be people coming from dynamic-typed, late-bound languages? Hence the references to e.g. Ruby? Certainly Rust's immediate mainstream "competition" all have the same constraints.
However, languages in the ML language family like StandardML and OCaml and Haskell do get away (sometimes) without explicit type signatures in function definitions. But I believe it's also considered good practice to declare them explicitly much of the time anyways. Because the alternative is, as the article pokes at, confusing error messages.
- steveklabnik 4y ago> It feels like the target audience for this post must be people coming from dynamic-typed, late-bound languages? You're picking up on something, for sure. When I originally put metaphorical pen to metaphorical paper, I intended to talk about static types vs TDD. Then this background got a bit long, so I decided to just make it its own thing, with that topic to follow. You're right on the "considered good practice" aspect, which I didn't call out specifically because I generally try not to frame things as "Rust good, other language bad," hence the "Rust vs what Rust would be with function-level inference."
- marcosdumay 4y ago> But I believe it's also considered good practice to declare them explicitly much of the time anyways. Much of the time is very different from always. For example, Haskell would be incredibly restrictive if every time you named a lambda you had to declare its type. People don't even declare most of their functions, just the top level ones. Always declaring the types would lead to large functions that are less general... what is common in Rust. (But that's not the only reason they are common in Rust.)
- dllthomas 4y agoTo be fair, you don't need to declare the types of your lambdas in Rust, either.
- pornel 4y agoYou can't even name their actual types, but you need to use generics that fully specify their arguments, return types, mutability and ownership.
- marcosdumay 4y agoRust lambdas are mostly equivalent to the stuff you don't name in Haskell. (But well, you can certainly name them, as I've done that; I don't remember if you need to declare their type; and it is almost never useful.)
- noloblo 4y agodo you mean lambdas in Haskell or monads? :P
- marcosdumay 4y agoOn the parenthesis I mean lambdas in Rust. My comment turned out to be completely unclear.