
2008/12/22 Raeck Zhao
Thank you very much for your reply! It is really helpful!
But I just found another 'problem', I just realize that the list does not support the user-defined data type? the list is also depending on the Eq function?
For example,
data Shape = Square | Triangle | Circle
when I type either
[Square, Triangle, Circle]
This is perfectly legal, but GHCi won't be able to print it, because there is no Show instance for Shape. You can declare one: instance Show Shape where show Square = "Square" show Triagle = "Triangle" show Circle = "Circle" This can be generated automatically when you declare the type, by using: data Shape = Square | Triangle | Circle deriving (Show)
or
Square == Square
Similarly, to use (==), you need an Eq instance, which can be defined much in the same way as the Show instance above (deriving also works on Eq -- don't generalize too hastily; not all classes work with deriving). Luke