by tome · 10y ago · 0 comments
To my mind a "pattern" is a structure you encode into a program where the language you are using doesn't allow you to encode that structure directly using the facilities it provides.
I understand that you don't need much plumbing, but you're still following a pattern that you have used elsewhere when working on these.
The beauty is that there's usually exactly one way of doing it (so by definition it is the simplest way). But if you're coming from a language based around mutability and are just in front of an Haskell REPL, I don't think you find this very easily.
In my mind patterns are about agreed-upon architectures for dealing with common issues. Another example that comes to mind in typed FP languages are wrapper types to prevent misuse of values (wrapping user input, unwrapping via "escape" calls).
When you have a problem, usually you'll have one or two canonical solutions come to mind. Those are the patterns for me.
Though given how simple everything usually is, it involves a lot less boilerplate. Choosing the right type is still essential.
On the other hand, I would say that your state monad in Python is a pattern, because there's no way of expressing the structure of the state monad in Python.