
3 Feb
2007
3 Feb
'07
12:54 p.m.
Hi Sergey, You wrote:
Suppose I want show Nothing to return "", and show (Just foo) return show foo. I don't seem to be able to. Looks like I either have to use some other function name, like `mShow'
That is correct. Show instances are supposed to follow the convention that "show x" is a Haskell expression that recreates x. In other words, Show is mainly used for debugging, for simple serialization, and for interactive use in a Haskell shell like ghci or hugs. If you need to create strings from a datatype for some other reason, use a different function name. If you need to do it for several datatypes, create your own class. Of course, Show does turn out to be more generally useful for numeric types. Hope this helps. Regards, Yitz