Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Question regarding error messages (Francesco Ariis)
   2. Re:  Question regarding error messages (David CAI)
   3. Re:  Question regarding error messages (Francesco Ariis)


----------------------------------------------------------------------

Message: 1
Date: Sun, 18 Jun 2017 18:49:09 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Question regarding error messages
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On Sun, Jun 18, 2017 at 05:02:13PM +0800, Choi Waikit wrote:
> Hi guys,
> 
> I have difficulty understanding how GHC determines what kind of error
> message to return. Could you help explain a bit ? Thanks !
> 
> The code can be accessed here <http://lpaste.net/356325>
> 
> My question is
> Why does calling `settleDown 9` return different error message from
> `settleDown "sting"` ?

Hello David,
    every time you write a number in a haskell source, it gets automagically
wrapped in `fromInteger` (actually, `fromInteger` if there isn't a dot,
`fromRational` otherwise). This is made to provide some kind of overloading.

`fromInteger` has signature:

    λ> :t fromInteger
    fromInteger :: Num a => Integer -> a

hence the different error with 9 and "string"!

Is it clear now?


------------------------------

Message: 2
Date: Mon, 19 Jun 2017 10:56:59 +0800
From: David CAI <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question regarding error messages
Message-ID:
        <CAJ7MPFoUnmXeecEWLzEdAbdCE6Mj_85kzEdgCAyr8=i2-hx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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.

Thanks,
David

On 19 June 2017 at 00:49, Francesco Ariis <[email protected]> wrote:

> On Sun, Jun 18, 2017 at 05:02:13PM +0800, Choi Waikit wrote:
> > Hi guys,
> >
> > I have difficulty understanding how GHC determines what kind of error
> > message to return. Could you help explain a bit ? Thanks !
> >
> > The code can be accessed here <http://lpaste.net/356325>
> >
> > My question is
> > Why does calling `settleDown 9` return different error message from
> > `settleDown "sting"` ?
>
> Hello David,
>     every time you write a number in a haskell source, it gets
> automagically
> wrapped in `fromInteger` (actually, `fromInteger` if there isn't a dot,
> `fromRational` otherwise). This is made to provide some kind of
> overloading.
>
> `fromInteger` has signature:
>
>     λ> :t fromInteger
>     fromInteger :: Num a => Integer -> a
>
> hence the different error with 9 and "string"!
>
> Is it clear now?
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170619/11c2c00f/attachment-0001.html>

------------------------------

Message: 3
Date: Mon, 19 Jun 2017 07:54:07 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Question regarding error messages
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

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!


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 108, Issue 9
*****************************************

Reply via email to