spent most of evening working on math, but here is the haskell stuff