These patches are used in ghc-asterius, and they may come in handy for other people too, hence this MR :)