Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Design patterns
- Singleton | top-level creation in main, pass it in as a Reader
- Factory | Just don't export the contstructor, and do export a smart constructor
- Factory Method | Add a type parameter to your ADT
- Abstract Factory | Use an existential with a typeclass constraint (aka use a type lambda on the RHS of data decl)
- Builder | Add a type parameter to your ADT and add a function parameter to your smart constructor that describes your "special construction process"
- Prototype | Don't export constructor, do export *nullary* smart constructor
- Object Pool | > Non-optimizing compiler can't even do this for you smh
- Chain of Responsibility | Function composition, or some more powerful Monad instance if you need it
- Command | Make an ADT for the command
- Interpreter | Use Free Monads and Cofree interpreters :P
- Iterator | literally the Foldable typeclass
- Mediator | Write a typeclass to define the interaction, or use two Free monad DSLs if it is very complex
- Observer | >State
- Observer (multithreaded) | Use MVars, TVars, or Chans (which are just MVar pairs)
- Strategy | Write a typeclass
- Template Method | Write a typeclass, plus some default implementations
- Visitor | I don't know what this is, but it looks like a Functor
- Null Object | Use one of: Either, Maybe, MonadFail m => m
- Adapter | Write a newtype and a give it a compatible instance
- Bridge, Composite | Category, Arrow, or Lens depending on what you need
- Decorator | Write a typeclass instance (I think)
- Flyweight | > Mutability. Nice meme
- Memento | Just write a function (YourObject -> StateRepr)
- Proxy | This is possible, but super contrived and useless in Haskell, so just don't use it
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement