<div dir="ltr"><div>In ghci try this:<br><br>> examples :: [Int]<br><br></div>It is enough that a is mentioned in the type of every function so that the compiler can figure out which instance is required when it is used. In size you have to pass an a in to figure out what type it is, but in examples, it is enough to know that it is a list of a's.<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 10, 2013 at 1:59 PM, Carmine Moleti <span dir="ltr"><<a href="mailto:carmine.moleti@gmail.com" target="_blank">carmine.moleti@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi to everyone,<br>
<br>
I'm learning Haskell going through Thompson's craft of functional<br>
programming (3rd ed).<br>
<br>
As of now I've reached Chapter 13 where classes definition and instances are<br>
discussed.<br>
<br>
At some point the "Info a" class is introduced which has the following<br>
interface:<br>
<br>
class Info a where<br>
examples :: [a]<br>
size :: a -> Int<br>
<br>
then it goes on explaining that every instance of that class must comply to<br>
the interface shown. So far so good.<br>
<br>
My perplexities start when actual instances are implemented.<br>
<br>
Take, for example the following one:<br>
<br>
instance Info Int where<br>
examples = [-100..100]<br>
size _ = 1<br>
<br>
I promptly tried to fiddle with this via ghci and while I was able to access<br>
the "size" function of the interface I have no clue about how to reach the<br>
"examples" part and that prevents me from understanding the next<br>
step when an instance of "Info [a]" is discussed.<br>
About that I don't quite get the definition of its "examples", and the<br>
reasons it is defined taking into accounts "all the one and two element<br>
lists that can be built up from exmaples of type a" (cit.)<br>
<br>
Can anyone shed some light about this, please?<br>
<br>
Thanks in advance for your help.<br>
<br>
Best regards,<br>
Carmine<br>
<br>
<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>