3 ms·
Wouldn't self/co-recursion be a safety of ML feature? Otherwise wouldn't you need mutation to do anything useful without worrying about your stack?
by Rickasaurus 14y ago
Wouldn't self/co-recursion be a safety of ML feature? Otherwise wouldn't you need mutation to do anything useful without worrying about your stack?
- steveklabnik 14y agoFrom a certain perspective, yes. You're confusing the tool with its purpose.
- Rickasaurus 14y agoWhat do you mean? Combinators are great (even if implemented imperatively) until you really care about performance and isn't that what this rust discussion is all about. Did you mean something other than combinators?
- steveklabnik 14y agoI mean that 'safety' means a wide variety of things, and you're conflating the PLT feature with the more general reason why that feature was needed. For example, above, you mention how TCO lets you use first-class functions to help you eliminate mutability. It's the elimination of mutability that's the safety here. Rust allows you to eliminate mutability through other means.
- dherman 14y agoI think you're mixing up tail recursion with general recursion. Rust absolutely supports recursion: the implementation uses segmented stacks to allow for stacks to grow dynamically. Tail call support is about not having the stack grow but only in the subset of recursive calls that are in tail position. So support for tail calls is not about safety but expressiveness, and Rust chooses to express iterative algorithms through other means, such as the iteration protocol that's built on top of higher-order functions. EDIT: Maybe I'm misreading you and you only mean the imperative nature of loops forces you to use mutation. Rust does not eschew mutation altogether. Even as a functional programmer myself, I'd argue pretty emphatically that mutation, particularly of local variables, is not a grave safety concern.