Abusing the algebra of algebraic data types – why does this work?

Disclaimer: A lot of this doesn’t really work quite right when you account for ⊥, so I’m going to blatantly disregard that for the sake of simplicity. A few initial points: Note that “union” is probably not the best term for A+B here–that’s specifically a disjoint union of the two types, because the two sides … Read more

How do you represent a graph in Haskell?

In shang’s answer you can see how to represent a graph using laziness. The problem with these representations is that they are very difficult to change. The knot-tying trick is useful only if you’re going to build a graph once, and afterward it never changes. In practice, should I actually want to do something with … Read more

Memory footprint of Haskell data types

(The following applies to GHC, other compilers may use different storage conventions) Rule of thumb: a constructor costs one word for a header, and one word for each field. Exception: a constructor with no fields (like Nothing or True) takes no space, because GHC creates a single instance of these constructors and shares it amongst … Read more

How can I see the full expanded contract of a Typescript type?

The quick info for a type displayed with IntelliSense often leaves something to be desired; you generally get a single representation for any given type, which may turn out to be too terse or even too verbose for your purposes. There are a few suggestions to make it more flexible (e.g., microsoft/TypeScript#25784 and microsoft/TypeScript#28508) so … Read more