2008/12/22 Raeck Zhao <span dir="ltr"><<a href="mailto:raeck@msn.com">raeck@msn.com</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
Thank you very much for your reply! It is really helpful!<br><br>But I just found another 'problem', I just realize that the list does not support the user-defined data type?<br>the list is also depending on the Eq function?<br>
<br>For example,<br><br>data Shape = Square | Triangle | Circle<br><br>when I type either<br><br>[Square, Triangle, Circle]</div></blockquote><div><br>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:<br>
<br><font face="courier new,monospace">instance Show Shape where<br> show Square = "Square"<br> show Triagle = "Triangle"<br> show Circle = "Circle"<br><br><font face="times new roman,serif">This can be generated automatically when you declare the type, by using:<br>
<br><font face="courier new,monospace">data Shape = Square | Triangle | Circle<br> deriving (Show)<br></font></font></font> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><br><br>or <br><br>Square == Square</div></blockquote><div><br>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).<br>
<br>Luke<br></div></div>