Gmail Calendar Documents Web Reader more »
Recently Visited Groups | Help | Sign in
Google Groups Home
ghc warning
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
ld  
View profile  
 More options Mar 4, 9:11 am
Newsgroups: comp.lang.haskell
From: ld <laurent.den...@gmail.com>
Date: Thu, 4 Mar 2010 06:11:38 -0800 (PST)
Local: Thurs, Mar 4 2010 9:11 am
Subject: ghc warning
When I compile

rint :: Int -> Double -> Double
rint d x = fromIntegral (round (x * 10^d)) / 10^d

GHC reports

main.hs:442:25:
    Warning: Defaulting the following constraint(s) to type `Integer'
             `Integral b' arising from a use of `round' at main.hs:
442:25-40
    In the first argument of `fromIntegral', namely
        `(round (x * 10 ^ d))'
    In the first argument of `(/)', namely
        `fromIntegral (round (x * 10 ^ d))'
    In the expression: fromIntegral (round (x * 10 ^ d)) / 10 ^ d

I tried various signature constraint to remove the warning (-Wall)
without success. I remember to have read something about this
"defaulting" problem in the Haskell type system so I am not sure that
a solution exist.

Any hint?  Is there any other solution to truncate a Floating to a
given number of digits?

thanks.

Laurent.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark T. B. Carroll  
View profile  
 More options Mar 4, 9:30 am
Newsgroups: comp.lang.haskell
From: "Mark T. B. Carroll" <Mark.Carr...@Aetion.com>
Date: Thu, 04 Mar 2010 09:30:12 -0500
Local: Thurs, Mar 4 2010 9:30 am
Subject: Re: ghc warning

ld <laurent.den...@gmail.com> writes:
> main.hs:442:25:
>     Warning: Defaulting the following constraint(s) to type `Integer'
>              `Integral b' arising from a use of `round' at main.hs:

It's wondering which integral type to use after rounding but before
converting back to Double. For instance,

rint :: Int -> Double -> Double
rint d x = fromIntegral (round (x * 10^d) :: Integer) / 10^d

Mark


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ld  
View profile  
 More options Mar 4, 9:48 am
Newsgroups: comp.lang.haskell
From: ld <laurent.den...@gmail.com>
Date: Thu, 4 Mar 2010 06:48:27 -0800 (PST)
Local: Thurs, Mar 4 2010 9:48 am
Subject: Re: ghc warning
On 4 mar, 15:30, "Mark T. B. Carroll" <Mark.Carr...@Aetion.com> wrote:

> ld <laurent.den...@gmail.com> writes:
> > main.hs:442:25:
> >     Warning: Defaulting the following constraint(s) to type `Integer'
> >              `Integral b' arising from a use of `round' at main.hs:

> It's wondering which integral type to use after rounding but before
> converting back to Double. For instance,

> rint :: Int -> Double -> Double
> rint d x = fromIntegral (round (x * 10^d) :: Integer) / 10^d

> Mark

Now that I see it, it looks obvious ;-)

Thanks,

Laurent


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google