Major refactor to support Haskell compilation

Signed-off-by: Austin Seipp <aseipp@pobox.com>