title: Adding a Show constraint when using GHC.Generics
body: <p>I am using GHC Generics. My use case is almost identical to <a href="https://wiki.haskell.org/GHC.Generics#Complete_working_example" rel="nofollow">the example in the wiki</a>, except that I am encoding and decoding gene sequences. </p>
  
  <p>This was all working fine, until I decided to keep a list of what I'd already read, so that I could report it to the user in case of an error. That means that I need to add a <code>Show</code> constraint to my default <code>get</code> implementation. The problem is that I can't figure out how to write the constraint. See the <code>-- HELP!!!</code> comment in the code below.</p>
  
  <pre><code>{-# LANGUAGE FlexibleContexts #-}
  {-# LANGUAGE DefaultSignatures #-}
  {-# LANGUAGE DeriveGeneric #-}
  {-# LANGUAGE TypeOperators #-}
  
  import Control.Monad.State.Lazy (StateT)
  import qualified Control.Monad.State.Lazy as S (put, get, gets)
  import Data.Functor.Identity (Identity)
  import Data.Word (Word8, Word16)
  import GHC.Generics
  
  type Sequence = [Word8]
  
  type Writer = StateT Sequence Identity
  
  type Reader = StateT (Sequence, Int, [String]) Identity
  
  class Genetic g where
    -- | Writes a gene to a sequence.
    put :: g -&gt; Writer ()
  
    default put :: (Generic g, GGenetic (Rep g)) =&gt; g -&gt; Writer ()
    put = gput . from
  
    -- | Reads the next gene in a sequence.
    get :: Reader (Either [String] g)
  
    default get :: (Generic g, GGenetic (Rep g), Show (Rep g x???)) -- HELP!!!
      =&gt; Reader (Either [String] g)
    get = do
      (_, start, _) &lt;- S.get
      a &lt;- gget
      (xs, stop, trace) &lt;- S.get
      let msg = show start ++ ':' : show stop ++ ' ' : show a
      S.put (xs, stop, msg:trace)
      return $ fmap to a
  
  class GGenetic f where
    gput :: f a -&gt; Writer ()
    gget :: Reader (Either [String] (f a))
  </code></pre>