[Haskell-beginners] Question regarding error messages
Francesco Ariis
fa-ml at ariis.it
Mon Jun 19 05:54:07 UTC 2017
On Mon, Jun 19, 2017 at 10:56:59AM +0800, David CAI wrote:
> Hi Francesco,
>
> Thanks for your reply! Just to make sure I understood, can I paraphrase
> your words as the following ?
>
> In the case of `settleDown 9`
> `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
> 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.
>
> In the case of `settleDown "hello"`
> 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.
Excellent explanation, that's exactly it!
More information about the Beginners
mailing list