Skip to content

Instantly share code, notes, and snippets.

@graninas
Last active September 2, 2023 13:47
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graninas/c71d2458d17bb8724b68dec6e38771c9 to your computer and use it in GitHub Desktop.
Save graninas/c71d2458d17bb8724b68dec6e38771c9 to your computer and use it in GitHub Desktop.
Haskell Design Patterns

Design patterns in Haskell

This is a list of patterns. I'm collecting this list with an idea to write a book similar to the GoF book.

My patterns:

  • Typed / Untyped pattern
  • Typed Avatar pattern (see Hydra and Node)
    • Typed Options pattern (see EulerHS)
  • Control Structure pattern (see CLI control structure in Hydra and similar in Node)
  • Declarative Protocol pattern (see CLI in Hydra & Node, TCP / UDP / JSON RPC in Node)
  • Record / Replay approach (see automatic whitebox testing and similar in Cirkit)
  • Interface / Runtime / Interpreter / Business Logic
  • Connectionless script (see KV DB & SQL DB in Hydra)
  • Poor man's dependent types with parsers

IoC & DI patterns / approaches:

  • ReaderT pattern
  • Service Handle pattern
  • mtl / Final Tagless
  • Approach from the Eric Torreborre's talk (from Haskell.love)
  • Hierarchical Free Monads
  • Extensible effect systems

Other patterns:

  • The Has Type Class pattern
  • Higher-Kinded Data
  • MVar Request-Response pattern
  • Abstract Interpreter pattern
  • Global state with IORef and unsafePerfomIO
  • Transactional monadic context (see STM, ST, hedis, SQL DB in Hydra)
  • WithResource pattern (bracket)
  • See also: Haskell mini-patterns

Architecture patterns:

  • Functional Core, Imperative Shell
  • Onion Architecture
  • 3-layer cake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment