Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8250657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:58:05+00:00 2026-06-07T23:58:05+00:00

I was hoping someone could explain the following behavior in GHCi, when using the

  • 0

I was hoping someone could explain the following behavior in GHCi, when using the function fromIntegral:

Prelude> let x = 1 :: Integer                                                                                                                                                    
Prelude> :t x                                                                                                                                                                    
x :: Integer                                                                                                                                                                     
Prelude> sqrt $ fromIntegral x                                                                                                                                                   
1.0                                                                                                                                                                              
Prelude> let y = fromIntegral x                                                                                                                                                  
Prelude> sqrt y                                                                                                                                                                  

<interactive>:181:1:                                                                                                                                                             
No instance for (Floating Integer)                                                                                                                                           
  arising from a use of `sqrt'                                                                                                                                               
Possible fix: add an instance declaration for (Floating Integer)                                                                                                             
In the expression: sqrt y                                                                                                                                                    
In an equation for `it': it = sqrt y                                                                                                                                         

Why does it matter whether I set y and then take its sqrt or just directly take the sqrt?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:58:07+00:00Added an answer on June 7, 2026 at 11:58 pm

    fromIntegral is polymorphic in its return type. So the type of y in your code could be expected to be Num a => a. This type would allow you to use y as the argument to sqrt without problem.

    However due to the monomorphism restriction, the type of y is not allowed to be polymorphic. Therefore it is defaulted to the default Num type, which is Integer.

    When you do sqrt $ fromIntegral x the monomorphism restriction does not apply because it only applies to global variables and you don’t store the result of fromIntegral in a variable this time.

    You can fix this issue by either adding a type signature to y (let y :: Num a => a; y = fromIntegal x) or by disabling the monomorphism restriction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was hoping someone could explain what is happening i the following code taken
I was hoping someone could help me with the following script: jQuery(document).ready(function($) { $(.infoBoxBtn
I am relatively new to Python and was hoping someone could explain the following
I was hoping someone could explain to me how eclipse automatically deploys to your
I was hoping someone could explain why my application when loaded uses varying amounts
I am having a problem with LINQ and I was hoping someone could explain
I was hoping someone could shed some light on a very odd behavior I've
I was hoping someone could explain to me what bad thing could happen in
I was hoping someone could explain something to me as I found my solution,
I was hoping someone could explain to me why i can't save new record?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.