Avoid partial list functions
This is a small fix which reimplements one fix of ghc/ghc@5943e739 which has already landed in the main branch on the ghc repo. This is the last requirement so that I can open a PR on the ghc repo to replace utils/hpc by a git submodule.