[Haskell] Overloading show

Stephan Zaubzer s.zaubzer at gmx.at
Fri Sep 10 18:37:29 EDT 2004

Hello Everyone!

I am relatively new to Haskell (actually it's my second day) and I have 
the following problem:
If I define a new datatype, for example a Binary tree, how can i use the 
show function to put an instance of my datatype into a String 
representation. I have seen in different Tutorials that there is a way 
for overloading the show function for my own type, and I tried out, what 
was presented in the tutorials, but it didn't work. Does somebody know, 
how to manage this?

Here my attempts:

data Entry a  = EmptyEntry | MakeEntry a a

showEntry :: (Show a) => Entry a -> String
showEntry EmptyEntry = "Empty"
showEntry MakeEntry a b = show a ++ ": " ++ show b

what am I doing wrong? I have seen this way on some tutorials.
btw: I am working with Hugs98

thank you in advance for your help

More information about the Haskell mailing list