Ported to ghc 7.6.3