Fix Trac #2668, and refactor TcDeriv
Fix Trac #2668, and refactor TcDeriv

TcDeriv deals with both standalone and ordinary 'deriving';
and with both data types and 'newtype deriving'.  The result
is really rather compilcated and ad hoc.  Ryan discovered
#2668; this patch fixes that bug, and makes the internal interfces
#more uniform.  Specifically, the business of knocking off 
type arguments from the instance type until it matches the kind of the
class, is now done by derivTyData, not mkNewTypeEqn, because the
latter is shared with standalone derriving, whree the trimmed
type application is what the user wrote.


jstolarek/ghc,wxwxwwxxx/ghc,ekmett/ghc,lukexi/ghc,ezyang/ghc,ml9951/ghc,shlevy/ghc,fmthoma/ghc,snoyberg/ghc,lukexi/ghc,vTurbine/ghc,sgillespie/ghc,nushio3/ghc,nathyong/microghc-ghc,urbanslug/ghc,AlexanderPankiv/ghc,fmthoma/ghc,mettekou/ghc,anton-dessiatov/ghc,hferreiro/replay,nathyong/microghc-ghc,anton-dessiatov/ghc,elieux/ghc,tibbe/ghc,fmthoma/ghc,gridaphobe/ghc,ryantm/ghc,snoyberg/ghc,mfine/ghc,vikraman/ghc,sdiehl/ghc,nomeata/ghc,urbanslug/ghc,acowley/ghc,christiaanb/ghc,snoyberg/ghc,vTurbine/ghc,TomMD/ghc,acowley/ghc,wxwxwwxxx/ghc,mcschroeder/ghc,hferreiro/replay,ghc-android/ghc,nushio3/ghc,ghc-android/ghc,frantisekfarka/ghc-dsi,fmthoma/ghc,spacekitteh/smcghc,lukexi/ghc-7.8-arm64,wxwxwwxxx/ghc,TomMD/ghc,TomMD/ghc,vikraman/ghc,nathyong/microghc-ghc,nathyong/microghc-ghc,mettekou/ghc,acowley/ghc,ml9951/ghc,shlevy/ghc,sdiehl/ghc,da-x/ghc,snoyberg/ghc,holzensp/ghc,ekmett/ghc,gridaphobe/ghc,gridaphobe/ghc,nkaretnikov/ghc,shlevy/ghc,olsner/ghc,siddhanathan/ghc,anton-dessiatov/ghc,GaloisInc/halvm-ghc,christiaanb/ghc,sgillespie/ghc,ml9951/ghc,da-x/ghc,sgillespie/ghc,ryantm/ghc,GaloisInc/halvm-ghc,lukexi/ghc-7.8-arm64,mcschroeder/ghc,siddhanathan/ghc,vTurbine/ghc,da-x/ghc,ghc-android/ghc,gridaphobe/ghc,GaloisInc/halvm-ghc,gridaphobe/ghc,shlevy/ghc,fmthoma/ghc,forked-upstream-packages-for-ghcjs/ghc,nushio3/ghc,green-haskell/ghc,ml9951/ghc,mcmaniac/ghc,gridaphobe/ghc,vTurbine/ghc,ml9951/ghc,frantisekfarka/ghc-dsi,forked-upstream-packages-for-ghcjs/ghc,mfine/ghc,ekmett/ghc,olsner/ghc,lukexi/ghc,anton-dessiatov/ghc,hferreiro/replay,urbanslug/ghc,da-x/ghc,christiaanb/ghc,tjakway/ghcjvm,mfine/ghc,mfine/ghc,gcampax/ghc,mettekou/ghc,mcschroeder/ghc,mfine/ghc,ilyasergey/GHC-XAppFix,ghc-android/ghc,snoyberg/ghc,lukexi/ghc,sdiehl/ghc,gcampax/ghc,olsner/ghc,ezyang/ghc,wxwxwwxxx/ghc,tjakway/ghcjvm,shlevy/ghc,forked-upstream-packages-for-ghcjs/ghc,acowley/ghc,lukexi/ghc-7.8-arm64,mettekou/ghc,elieux/ghc,oldmanmike/ghc,da-x/ghc,urbanslug/ghc,mcschroeder/ghc,ezyang/ghc,anton-dessiatov/ghc,oldmanmike/ghc,lukexi/ghc-7.8-arm64,tjakway/ghcjvm,GaloisInc/halvm-ghc,tibbe/ghc,gcampax/ghc,sdiehl/ghc,sdiehl/ghc,hferreiro/replay,sgillespie/ghc,tibbe/ghc,jstolarek/ghc,mettekou/ghc,sdiehl/ghc,elieux/ghc,mcmaniac/ghc,oldmanmike/ghc,elieux/ghc,ilyasergey/GHC-XAppFix,shlevy/ghc,ezyang/ghc,AlexanderPankiv/ghc,green-haskell/ghc,mcmaniac/ghc,olsner/ghc,spacekitteh/smcghc,ilyasergey/GHC-XAppFix,jstolarek/ghc,tibbe/ghc,sgillespie/ghc,sgillespie/ghc,fmthoma/ghc,mettekou/ghc,nomeata/ghc,ezyang/ghc,vikraman/ghc,GaloisInc/halvm-ghc,acowley/ghc,green-haskell/ghc,ml9951/ghc,ryantm/ghc,nushio3/ghc,forked-upstream-packages-for-ghcjs/ghc,christiaanb/ghc,vTurbine/ghc,holzensp/ghc,holzensp/ghc,siddhanathan/ghc,sdiehl/ghc,gcampax/ghc,gcampax/ghc,oldmanmike/ghc,bitemyapp/ghc,siddhanathan/ghc,mcschroeder/ghc,acowley/ghc,ml9951/ghc,oldmanmike/ghc,frantisekfarka/ghc-dsi,olsner/ghc,TomMD/ghc,mettekou/ghc,snoyberg/ghc,GaloisInc/halvm-ghc,elieux/ghc,green-haskell/ghc,siddhanathan/ghc,vikraman/ghc,lukexi/ghc-7.8-arm64,ezyang/ghc,nomeata/ghc,vikraman/ghc,green-haskell/ghc,spacekitteh/smcghc,ekmett/ghc,jstolarek/ghc,jstolarek/ghc,nathyong/microghc-ghc,GaloisInc/halvm-ghc,elieux/ghc,christiaanb/ghc,mfine/ghc,siddhanathan/ghc,ghc-android/ghc,ghc-android/ghc,nkaretnikov/ghc,mfine/ghc,AlexanderPankiv/ghc,vTurbine/ghc,wxwxwwxxx/ghc,holzensp/ghc,hferreiro/replay,siddhanathan/ghc,mcmaniac/ghc,sgillespie/ghc,forked-upstream-packages-for-ghcjs/ghc,tjakway/ghcjvm,AlexanderPankiv/ghc,shlevy/ghc,nomeata/ghc,ml9951/ghc,spacekitteh/smcghc,hferreiro/replay,oldmanmike/ghc,nushio3/ghc,nkaretnikov/ghc,anton-dessiatov/ghc,snoyberg/ghc,frantisekfarka/ghc-dsi,christiaanb/ghc,fmthoma/ghc,AlexanderPankiv/ghc,olsner/ghc,nushio3/ghc,tjakway/ghcjvm,nkaretnikov/ghc,oldmanmike/ghc,mcschroeder/ghc,TomMD/ghc,nathyong/microghc-ghc,urbanslug/ghc,olsner/ghc,nushio3/ghc,ezyang/ghc,ekmett/ghc,forked-upstream-packages-for-ghcjs/ghc,TomMD/ghc,bitemyapp/ghc,holzensp/ghc,vikraman/ghc,da-x/ghc,vTurbine/ghc,AlexanderPankiv/ghc,ghc-android/ghc,nkaretnikov/ghc,tjakway/ghcjvm,bitemyapp/ghc,urbanslug/ghc,frantisekfarka/ghc-dsi,AlexanderPankiv/ghc,acowley/ghc,wxwxwwxxx/ghc,elieux/ghc,gcampax/ghc,hferreiro/replay,christiaanb/ghc,tjakway/ghcjvm,ilyasergey/GHC-XAppFix,spacekitteh/smcghc,nkaretnikov/ghc,lukexi/ghc,forked-upstream-packages-for-ghcjs/ghc,bitemyapp/ghc,nathyong/microghc-ghc,wxwxwwxxx/ghc,anton-dessiatov/ghc,nkaretnikov/ghc,da-x/ghc,tibbe/ghc,bitemyapp/ghc,gcampax/ghc,mcmaniac/ghc,TomMD/ghc,urbanslug/ghc,vikraman/ghc,ryantm/ghc,nomeata/ghc,mcschroeder/ghc,ryantm/ghc,gridaphobe/ghc