title: How does Haskell choose methods for instances of type classes?
body: <p>I was trying to understand why Haskell's <code>show</code> treats
  a list of chars different from a list of e.g. integers
  even without the <code>FlexibleInstances</code> Pragma.</p>
  
  <p>Having read through the documentation of <code>Show</code>, I realized
  that I don't really understand how Haskell chooses methods
  for instances of type classes.</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>class MyShow a where
      myShow :: a -&gt; String
      myShowList :: [a] -&gt; String
      myShowTuple :: (a, b) -&gt; String
  
      myShowList xs = "Default List Implementation"
      myShowTuple t = "Default Tuple Implementation"
  
  instance MyShow Char where
      myShow c = "One Char"
      myShowList xs = "List of Chars"
      myShowTuple t = "Char Tuple"
  
  instance MyShow Int where
      myShow n = "One Int"
      myShowList xs = "List of Integers"
      myShowTuple t = "Int Tuple"
  
  instance MyShow Float where
      myShow n = show n
  
  instance (MyShow a) =&gt; MyShow [a] where
      myShow = myShowList
  
  instance (MyShow a) =&gt; MyShow (a, b) where
      myShowTuple t = "foo"
      myShow = myShowTuple
  </code></pre>
  
  <p>Now if I call e.g.</p>
  
  <pre><code>myShow (5::Int,5::Int)
  </code></pre>
  
  <p>I would expect that Haskell thinks
  'Oh, <code>myShow</code> got a tuple as an argument. Let's see which
  implementation I have to call.'
  and chooses the last one which in return would result
  in <code>"foo"</code>.
  Obviously, this is not the case.
  Haskell seems to look at the content of the tuple (namely
  the type of <code>a</code>) and decides to call the corresponding method,
  resulting in <code>"Int Tuple"</code>.</p>
  
  <p>Why is this?</p>