4 ms·
A better reason: Tail recursion lets you implement "while" if you miss it.
by olavk 14y ago
A better reason: Tail recursion lets you implement "while" if you miss it.
- lmm 14y agoThat explains why I want tail recursion in lisp, a language that doesn't have "while". But it doesn't explain why I would ever want or need tail recursion in python, which already has while. In the same way, I can see why I want monads in Haskell. But why would I ever want or need monads in a language that has first-class imperative constructs?
- olavk 14y agoAgreed about tail recursion in Python, promoting recursion as an alternative to loops is contrary to the sprit of Python and "one obvious way to do it". Monads vs imperative languages is a bit different though, since Haskell-style monads are more than just a way of allowing an imperative style. For example many other features like list comprehensions and parsing is also based on monads in Haskell. However the real value of Haskell-style monads is that it is clear when you don't use them. So it is explicit in the type system which functions have side effects and which don't.
- lmm 14y ago>Monads vs imperative languages is a bit different though, since Haskell-style monads are more than just a way of allowing an imperative style. For example many other features like list comprehensions and parsing is also based on monads in Haskell. So maybe monads are useful for implementing language internals. But if we assume my language has list comprehensions and a parser (however they're implemented internally), what would I as a user of the language want monads for? I keep hearing that monads are great, but every code example I've seen using them seems like something that I could do more easily in python, without a monad. So I'd really like to see any examples of code that you would want to write using monads, even in a language that has imperative constructs.
- talaketu 14y agoCheck some of the pyparsing examples.