This happens syntactically, for classes known to the compiler. instance definitions are added for every data constructor produced by "data". https://www.haskell.org/onlinereport/derived.html#derived-appendix http://stackoverflow.com/questions/3864647/how-does-deriving-work-in-haskell In GHC, https://wiki.haskell.org/Template_Haskell can produce the necessary syntax: https://wiki.haskell.org/Template_haskell/Instance_deriving_example For Prelude's types like integers, tuples, lists, strings, booleans, etc., https://hackage.haskell.org/package/base-4.6.0.1/docs/src/GHC-Show.html shows the code.