| ▲ | IshKebab 2 hours ago | ||||||||||||||||
Nice! I think it's pretty widely agreed that requiring type annotations at the function level is a good thing anyway. Apparently it's considered good practice in Haskell even though Haskell doesn't require it. I've also worked with OCaml code that didn't do it and you lose a lot of the advantages of static typing. Definitely worse. Rust got it right. | |||||||||||||||||
| ▲ | dragonwriter 12 minutes ago | parent | next [-] | ||||||||||||||||
Type annotations on functions in Haskell (or similar languages) are useful for: 1. leveraging the type checker to verify (aspects of) the correctness of your function, and 2. communicating intent to humans I've found in my own explorations with Haskell that its useful to write with functions with them, then verify that they work, and then remove them to see what the inferred would be (since it already compiled with the annotation, the inferred type will either be identical to or more general than the previously declared type), and generally (because it is good practice to have a declared type), replace the old declared type with the inferred type (though sometimes at this point also changing the name.) | |||||||||||||||||
| ▲ | toolslive 2 hours ago | parent | prev | next [-] | ||||||||||||||||
what if your IDE can show the type of any expression as a tooltip ? Would you still think the same? | |||||||||||||||||
| |||||||||||||||||
| ▲ | Quekid5 an hour ago | parent | prev [-] | ||||||||||||||||
> I think it's pretty widely agreed that requiring type annotations at the function level is a good thing anyway. Apparently it's considered good practice in Haskell even though Haskell doesn't require it. In Haskell-land: At the global scope, yes, that's considered good practice, especially if the function is exported from a module. When you just want a local helper function for some tail-recursive fun it's a bit of extra ceremony for little benefit. (... but for Rust specifically local functions are not really a big thing, so... In Scala it can be a bit annoying, but the ol' subtyping inference undecidability thing rears its ugly head there, so there's that...) | |||||||||||||||||
| |||||||||||||||||