How to view the generated code for derived instances / deriving in Haskell

For stack:

stack build --ghc-options="-ddump-deriv"

Output in my specific case is: .stack-work/dist/x86_64-linux-nix/Cabal-2.4.0.1/build/app/app-tmp/src/


You can use the the -ddump-deriv GHC option to see the code for derived instances:

ghc -ddump-deriv test.hs 
[1 of 1] Compiling Test             ( test.hs, test.o )

==================== Derived instances ====================
Derived instances:
  instance GHC.Show.Show Test.FooBar where
    GHC.Show.showsPrec _ Test.Foo = GHC.Show.showString "Foo"
    GHC.Show.showsPrec _ Test.Bar = GHC.Show.showString "Bar"
    GHC.Show.showList = GHC.Show.showList__ (GHC.Show.showsPrec 0)


Generic representation:

  Generated datatypes for meta-information:

  Representation types: