Merged in Haskell implementation from SpaceParty