3 ms·
> infer recursive functions Any of the mainstream functional languages (which are most likely to have type inference) can infer the types of all functions, unl
by mrkgnao 9y ago
> infer recursive functions
Any of the mainstream functional languages (which are most likely to have type inference) can infer the types of all functions, unless you use funky language extensions that make type inference undecidable. Rust has a Hindley-Milner system, so it should be able to "infer recursive functions" too (but I can't say for sure since I don't use it).
- fny 9y agoI've tried in Rust, and it requires a return definition, as do most mainstream functional languages. Also, mainstream functional languages aren't truly mainstream: I'd struggle to find devs who could help me in consulting gigs.
- igouy 9y agolet rec factorial n = if n = 0 || n = 1 then 1 else n * factorial (n - 1) F#
- mrkgnao 9y agoHaskell: factorial n = if n < 2 then 1 else n * factorial (n - 1) I think the OCaml version will look almost exactly like the F# one.
- mrkgnao 9y agoI'm pretty sure that's just "administrative" and imposed by the syntax (e.g. think Java/C++ function declaration syntax), instead of being something the compiler can't infer. Thanks for clearing this up, though.
- steveklabnik 9y agoIt was a design decision, yes. We could infer them if we wanted to, but we don't.