Strange pattern matching with functions instancing Show

Posted by Sean D on Stack Overflow See other posts from Stack Overflow or by Sean D
Published on 2010-04-28T15:52:29Z Indexed on 2010/04/28 16:03 UTC
Read the original article Hit count: 210

Filed under:
|

So I'm writing a program which returns a procedure for some given arithmetic problem, so I wanted to instance a couple of functions to Show so that I can print the same expression I evaluate when I test. The trouble is that the given code matches (-) to the first line when it should fall to the second.

{-# OPTIONS_GHC -XFlexibleInstances #-}

instance Show (t -> t-> t) where  
 show (+) = "plus"
 show (-) = "minus"  

main = print [(+),(-)]

returns

[plus,plus]

Am I just committing a motal sin printing functions in the first place or is there some way I can get it to match properly?

edit:I realise I am getting the following warning:

Warning: Pattern match(es) are overlapped
         In the definition of `show': show - = ...

I still don't know why it overlaps, or how to stop it.

© Stack Overflow or respective owner

Related posts about haskell

Related posts about pattern-matching