[Haskell-cafe] Alternate instance Show (Maybe a)?

Yitzchak Gale gale at sefer.org
Sat Feb 3 12:54:17 EST 2007

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.


More information about the Haskell-Cafe mailing list