Re:Rust vs. Haskell
by bryanlarsen on Tuesday February 14, 2023 @08:31AM
(#34788968)
pub functions: should be explicit
module functions: if I chose, I'd let them be derived, but I'm relatively indifferent
inner functions: should be allowed to be derived, IMO. They're very infrequently used so this choice doesn't have much impact.
You can use closures as functions with type inferred signatures
Re:Rust vs. Haskell
by bryanlarsen on Tuesday February 14, 2023 @09:52AM
(#34790126)
Closures capture variables so have significant differences compared to inner functions. Capture can affect lifetimes so the difference is significant in Rust.
Closures don't have to capture variables. If they don't then they're equivalent to functions.
Re:Rust vs. Haskell
by bryanlarsen on Tuesday February 14, 2023 @12:00PM
(#34792270)
That's what I thought too, but I fixed some compiler errors by turning a closure into an inner function. Probably a PBKAC, but...
Re:Rust vs. Haskell
by LegionMammal978 on Tuesday February 14, 2023 @06:07PM
(#34797530)
Perhaps it's due to the fact that you can't really have type-generic closures in Rust: once the compiler has inferred one type, the closure cannot be used with another type. In contrast, inner functions can have any number of additional type parameters.
You don't need it for all function declarations though, there are many trivial cases where type signatures don't add value. Consider that you probably would prefer most of the variables within a function to be inferred for you by the compiler. A similar thing could be said about the most of the functions within a given module. Important interface methods can be defined explicitly though, for extra clarity and self-documenting purposes.