4 ms·
Because passing around tuples and pattern matching against them becomes tiring. So you wrap that code repetition pattern around in a State. The State monad is i
by flebron 13y ago
Because passing around tuples and pattern matching against them becomes tiring. So you wrap that code repetition pattern around in a State. The State monad is implemented in terms of the language itself, it's not adding anything to the language in terms of computability or expressiveness. It's simply making you type less, for something you could already write in the language itself.
All of these things - Functors, Applicative, Monads, Lenses - are all design patterns in functional programming. In the same way you can use an Observer pattern in OOP, you can use a Monad pattern in functional programming. Neither adds neither computational nor expressive power to the language, but it does avoid code repetition.
- tel 13y agoBut that doesn't answer as to why you'd want to use tuples and pattern matching if your language has first class mutability.
- Mithaldu 13y agoThank you, that makes sense to me, and i hope i understood it right. Could you please check https://news.ycombinator.com/item?id=7076961 https://news.ycombinator.com/item?id=7076961 to see if my understanding is right?