Skip to content

Instantly share code, notes, and snippets.

Stephen Diehl (@smdiehl )

Since I wrote these slides for a little user group talk I gave two years ago they have become a surprisingly popular reference. I decided to actually turn them into a proper skimmable reference for intermediate and advanced level Haskell topics that don't necessarily have great coverage or that tend be somewhat opaque as to where to get going, and then aggregate a bunch of the best external resources for diving into those subjects with more depth. Hopefully it still captures the "no bullshit brain dump" style that seemed to be liked.

The source for all code is available here. If there are any errors or you think of a more illustrative example feel free to submit a pull request.

@tdoris
tdoris / Promises.md
Last active November 10, 2023 01:15

Does Haskell make promises it can't keep?

or The big problem with wrapping numeric types

When coding financial calculations, it's common to have a variety of numeric values such as Quantity, Price, Amount and so on. In quant finance, these usually refer to the Price observed in the market, a Quantity of shares. A Quantity of shares all traded at a given Price in a given currency will give you an Amount of that currency (the total value of the trade).

It's simple and fun exercise to write the functions you'd need to perform all the correct ways of combining Price, Quantity and Amount. There are a couple of things that don't work as you might expect (e.g., multiplication is ok but you need to think about division semantics.).

Many Haskell tutorials encourage the coder to wrap Double and Int in newtypes like this, so the compiler can help by detecting incorrect combinations of the different types, and so the code documents itself better. e.g.