title: Haskell: Using the correct instance for a type wrapped in another type
body: <p>Say we have the following code, where a couple of types end up being place inside two other types, the outer-most of which is a GADT:</p>
  
  <pre><code>{-# LANGUAGE FlexibleInstances,
               GADTSyntax,
               GADTs,
               OverlappingInstances,
               StandaloneDeriving #-}
  
  data SomeType1 = SomeType1 deriving Show
  data SomeType2 = SomeType2 deriving Show
  
  class SomeClass d where
  
  instance SomeClass SomeType1 where
  instance SomeClass SomeType2 where
  
  data WrapperType t where
    WrapperType :: (SomeClass t, Show t) =&gt; t -&gt; (WrapperType t)
  
  instance Show (WrapperType SomeType1) where
    show (WrapperType d) = "correct"
  
  instance Show (WrapperType t) where
    show (WrapperType d) = "incorrect"
  
  data ListWrap where
    ListWrap :: [(WrapperType d)] -&gt; ListWrap
  
  deriving instance Show ListWrap
  </code></pre>
  
  <p>Now, writing <code>[WrapperType SomeType1]</code> gives me what I want:</p>
  
  <pre><code>*MyModule&gt; [WrapperType SomeType1]
  [correct]
  </code></pre>
  
  <p>But as soon as I put it inside <code>ListWrap</code> I get the wrong <code>Show</code> instance picked to display the contents:</p>
  
  <pre><code>*MyModule&gt; ListWrap [WrapperType SomeType1]
  ListWrap [incorrect]
  </code></pre>
  
  <p>There must be something about type classes and/or GADTs that I'm failing to understand -- what could it be?</p>