<div dir="ltr">Hi Francesco,<br><br>Thanks for your reply! Just to make sure I understood, can I paraphrase your words as the following ?<br><br>In the case of `settleDown 9`<br>`settleDown 9` is first translated to `settleDown $ fromInteger 9`. Since fromInteger lies in Num type class and settleDown's signature is: settleDown :: Mood -> Mood, the compiler tries to look for <br>an instance for Num typeclass so that it can resolve which `fromInteger` method to call. Therefore it doesn't show a type mismatch error but hint for implementing a typeclass.<br><br>In the case of `settleDown "hello"`<br>There's no preprocessing for "hello" so its type remains [Char]. Since settleDown has type Mood -> Mood, Mood and [Char] are not compatible, therefore the compiler shows a type mismatch error.<br><br>Thanks,<br>David<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 19 June 2017 at 00:49, Francesco Ariis <span dir="ltr"><<a href="mailto:fa-ml@ariis.it" target="_blank">fa-ml@ariis.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sun, Jun 18, 2017 at 05:02:13PM +0800, Choi Waikit wrote:<br>
> Hi guys,<br>
><br>
> I have difficulty understanding how GHC determines what kind of error<br>
> message to return. Could you help explain a bit ? Thanks !<br>
><br>
</span>> The code can be accessed here <<a href="http://lpaste.net/356325" rel="noreferrer" target="_blank">http://lpaste.net/356325</a>><br>
<span class="">><br>
> My question is<br>
> Why does calling `settleDown 9` return different error message from<br>
> `settleDown "sting"` ?<br>
<br>
</span>Hello David,<br>
every time you write a number in a haskell source, it gets automagically<br>
wrapped in `fromInteger` (actually, `fromInteger` if there isn't a dot,<br>
`fromRational` otherwise). This is made to provide some kind of overloading.<br>
<br>
`fromInteger` has signature:<br>
<br>
λ> :t fromInteger<br>
fromInteger :: Num a => Integer -> a<br>
<br>
hence the different error with 9 and "string"!<br>
<br>
Is it clear now?<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>