3 ms·
Having explicit function types prevents Rust from feeling like an algebra problem. Languages like Haskell and OCaml make writing generic functions super simple
by hardwaregeek 4y ago
Having explicit function types prevents Rust from feeling like an algebra problem. Languages like Haskell and OCaml make writing generic functions super simple and elegant, but it comes at the cost of having abstraction be the default. Therefore you end up reading signatures where the mental process is "so I have a parameter x of type a, then a parameter f of type a -> m b, then a return type of m b, hmm now in this case m = List, a = Int, b = Float". You end up having to do a lot of substitution and manual unification in your head. Which, to be fair, some people enjoy and find useful. More power to them!
On the flip side, forcing type signatures means that I tend to shy away from more sophisticated types like fancy closures with lifetimes. Which can be frustrating because the usage is simple, but the type is sometimes not. But I think it's fine for function signatures to be a little harder to write for library authors and a little easier to understand for library users.
- marcosdumay 4y ago> You end up having to do a lot of substitution and manual unification in your head. Hum... I don't think I do that. I did a lot when I was first learning it, but not now. Now there's some pattern matching (`f :: a -> m b` immediately says something) and a lot of generalization (so I don't think "I have a list, I want to apply a function"; I think "I will apply a function, I want something I can map"). The `Applicative m => m a` comes before the `[a]`.
- brundolf 4y agoIDEs close the gap a lot on type inference. Being able to hover a symbol and see the inferred type without mentally inferring it yourself is important