<div dir="ltr"><div><div><div>Hi,<br><br>instance Show Stat where<br></div> show (a, b) = "the value of " ++ a ++ " is " ++ show b<br><br></div>I pretty sure you need also enable <code class="">TypeSynonymInstances </code><code class="">extension. One way to do it is to add "{-# LANGUAGE </code><code class="">TypeSynonymInstances #-}" just at the beginning of your module.<br><br></code></div><code class="">Best wishes<br></code></div><div class="gmail_extra"><br><div class="gmail_quote">2015-12-04 1:16 GMT+03:00 Murilo Winter <span dir="ltr"><<a href="mailto:murilo.winter@gmail.com" target="_blank">murilo.winter@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-family:Arial,Helvetica,sans-serif;font-size:13px">Hello,</span><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px">As part of my exercise, I have to create an instance of the show typeclass for a given data type defined as:</div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><ol start="1" style="padding:0px;border:none;outline:0px;font-size:14px;vertical-align:baseline;font-family:Consolas,monospace;line-height:25px;list-style:none!important;background-color:rgb(0,0,0)"><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"><b style="color:rgb(149,228,84)">type </b><font style="margin:0px;padding:0px;border:0px" color="#ffffff">stat </font><b style="color:rgb(149,228,84)">= (</b><font style="margin:0px;padding:0px;border:0px" color="#ffffff">String</font><b style="color:rgb(149,228,84)">, <span style="margin:0px;padding:0px;border:0px;color:rgb(255,255,255);font-weight:normal">Int</span>)</b><font style="margin:0px;padding:0px;border:0px" color="#ffffff"> </font></span></span></li></ol></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><u>If</u> it was a data type, like:</div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><ol start="1" style="padding:0px;border:none;outline:0px;font-size:14px;vertical-align:baseline;color:rgb(92,92,92);font-family:Consolas,monospace;line-height:25px;margin:0px 0px 1px!important;list-style:none!important;background-color:rgb(0,0,0)"><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;color:inherit;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:white;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(149,228,84);font-weight:bold;background-color:inherit">data</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">TrafficLight</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(138,198,242);background-color:inherit"> = </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Red</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(138,198,242);background-color:inherit"> | </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Yellow</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(138,198,242);background-color:inherit"> | </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Green</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span></span></li></ol></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px">It would be as simple as doing:</div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><ol start="1" style="padding:0px;border:none;outline:0px;font-size:14px;vertical-align:baseline;color:rgb(92,92,92);font-family:Consolas,monospace;line-height:25px;list-style:none!important;background-color:rgb(0,0,0)"><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;color:inherit;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:white;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(149,228,84);font-weight:bold;background-color:inherit">instance</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Show</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">TrafficLight</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(149,228,84);font-weight:bold;background-color:inherit">where</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span></span></li><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:white;background-color:inherit"> show <span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Red</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(138,198,242);background-color:inherit"> = </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(255,255,153);background-color:inherit">"Red light"</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span></span></li><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;color:inherit;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:white;background-color:inherit"> show <span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Yellow</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(138,198,242);background-color:inherit"> = </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(255,255,153);background-color:inherit">"Yellow light"</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span></span></li><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:white;background-color:inherit"> show <span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Green</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(138,198,242);background-color:inherit"> = </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(255,255,153);background-color:inherit">"Green light"</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span></span></li></ol></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px">However, I do not know how to declare the instance for a type, and then how to access its elements (String and Int).</div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px">This is what I have so far, which does not work:</div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><ol start="1" style="padding:0px;border:none;outline:0px;font-size:14px;vertical-align:baseline;font-family:Consolas,monospace;line-height:25px;color:rgb(92,92,92);list-style:none!important;background-color:rgb(0,0,0)"><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;color:inherit;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:white;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(149,228,84);font-weight:bold;background-color:inherit">instance</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit">Show</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> Stat </span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(149,228,84);font-weight:bold;background-color:inherit">where</span><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;background-color:inherit"> </span></span></li><li style="line-height:18px;border:0px;outline:0px;vertical-align:baseline;margin:0px!important;padding:0px 3px!important;list-style:none!important;background-color:inherit"><span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:white;background-color:inherit"> show stat(a,b) <span style="margin:0px;padding:0px;border:none;outline:0px;vertical-align:baseline;color:rgb(138,198,242);background-color:inherit">= </span></span><span style="margin:0px;padding:0px;border:0px;color:rgb(255,255,255)">a</span></li></ol></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><div style="margin:0px;padding:0px;border:0px">instance Show Stat where</div><div style="margin:0px;padding:0px;border:0px"> show stat(a b) = b</div></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px">(imagine, for example, I desire to write" the value of "String" is "Int").</div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px"><br></div><div style="margin:0px;padding:0px;border:0px;font-family:Arial,Helvetica,sans-serif;font-size:13px">Thanks,</div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>