Skip to content

Instantly share code, notes, and snippets.

@tmountain
Created October 30, 2018 12:54
Show Gist options
  • Save tmountain/61851bee705887509a7a58ceda28c9b8 to your computer and use it in GitHub Desktop.
Save tmountain/61851bee705887509a7a58ceda28c9b8 to your computer and use it in GitHub Desktop.
Scalable program architectures
Haskell design patterns differ from mainstream design patterns in one important way:
Conventional architecture: Combine a several components together of type A to generate a "network" or "topology" of type B
Haskell architecture: Combine several components together of type A to generate a new component of the same type A, indistinguishable in character from its substituent parts
This distinction affects how the two architectural styles evolve as code bases grow.
The conventional architecture requires layering abstraction on top of abstraction:
Oh no, these Bs are not connectable, so let's make a network of Bs and call that a C.
Well, I want to assemble several Cs, so let's make a network of Cs and call that a D
...
Wash, rinse, and repeat until you have an unmanageable tower of abstractions.
With a Haskell-style architecture, you don't need to keep layering on abstractions to preserve combinability. When you combine things together the result is still itself combinable. You don't distinguish between components and networks of components.
In fact, this principle should be familiar to anybody who knows basic arithmetic. When you combine a bunch of numbers together you get back a number:
3 + 4 + 9 = 16
Zero or more numbers go in and exactly one number comes out. The resulting number is itself combinable. You don't have to learn about "web"s of numbers or "web"s of "web"s of numbers.
If elementary school children can master this principle, then perhaps we can, too. How can we make programming more like addition?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment