Skip to content

Instantly share code, notes, and snippets.

@aaditmshah
aaditmshah / design-patterns-in-haskell.md
Created June 12, 2024 04:03
Design Patterns in Haskell

Design Patterns in Haskell

Creational Patterns

Factory Method

  1. Create a Product type class.
  2. Create an existential type SomeProduct for the Product type class.
  3. Create a Factory type class with a createProduct method.
@aaditmshah
aaditmshah / queue.ts
Created August 10, 2023 09:37
Chris Okasaki's Lazy Persistent Queue
type Assert = (condition: boolean, message: string) => asserts condition;
const assert: Assert = (condition, message) => {
if (!condition) throw new Error(message);
};
type List<A> = Cons<A> | Empty;
interface Cons<out A> {
type: 'Cons';