Think of it this way:

-- Here is some data representing the typeclass 'Show'
data ShowDict a = ShowD (a -> String)
show :: ShowDict a -> a -> String
show (ShowD f) a = f a

-- Here's a sample implementation for Strings
showString :: ShowDict String
showString = ShowD (\s -> "\"" ++ escape s ++ "\"") where
   escape = concatMap escapeChar
   escapeChar '\\' = "\\\\"
   escapeChar '"' = "\\\""
   escapeChar c = [c]

-- Here's an implementation for pairs that uses the implementation for each piece of the pair
showPair :: ShowDict a -> ShowDict b -> ShowDict (a,b)
showPair (ShowD sa) (ShowD sb) = ShowD (\(a,b) -> "(" ++ sa a ++ ", " ++ sb b ++ ")")

-- Here is what you are asking for
implementMe :: ShowDict (a,b) -> ShowDict a
implementMe  = ????


On Thu, May 19, 2011 at 2:08 PM, Andrew Coppin <andrewcoppin@btinternet.com> wrote:
 Cannot deduce (Show x) from context (Show (x, y)).
 Cannot deduce (Show y) from context (Show (x, y)).

Um... seriously?

>From Prelude, we have

 Show x, Show y => Show (x, y)

So clearly it works in the forward direction. But apparently not in the reverse direction.

Is this a bug or a feature? (I.e., is there some obscure possibility I haven't thought of which means that doing the reverse inference would be incorrect?)

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe