Ported to GHC 7.6.2