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 8589703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:07:13+00:00 2026-06-11T23:07:13+00:00

In Haskell, I am having some problems defining functions because the types of my

  • 0

In Haskell, I am having some problems defining functions because the types of my argument does not match the required type.

For example, I would like to write a function that takes an n :: Int and produces the list of integers from 1 to the floor of the square root of n. Hence I would to have a function such as:

list :: Int -> [Int]

Originally I defined the function as follows:

list :: Int -> [Int]

list n = [1 .. floor (sqrt n)]

When I loaded the sript, there is an error message of the types not matching. However, I am not sure if I am not matching the type of the sqrt function or the floor function. The error message is the follow:

No instance for (Floating Int)
  arising from a use of 'sqrt' at pe142.hs:6:22-27
Possible fix: add an instance declaration for (Floating Int)
In the first argument of 'floor', namely '(sqrt n)'
In the expression: floor (sqrt n)
In the expression: [1 .. floor (sqrt n)]
Failed, modules loaded: none.

Could someone explain to me what is causing the error and how it can be fixed?

  • 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-11T23:07:14+00:00Added an answer on June 11, 2026 at 11:07 pm

    sqrt requires an argument of the Floating class, e.g. a Double. You’re passing it an Int, which is not an instance of the Floating class – that’s what the error message is telling you.

    So to fix the error, convert your Int to a Double before calling sqrt. You can use the fromIntegral function for that.

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

Sidebar

Related Questions

I'm switching from Haskell to OCaml but I'm having some problems. For instance, I
I need to make a Coke Vending Machine in Haskell, but I'm having some
I'm having a bit problem with reading argument value in haskell: I'm having options
Hello I am new at Haskell and i'm having problems trying to get this
I'm trying to convert some Haskell code to F# but I'm having some trouble
I am writing some functions for graphs in Haskell, and I want to check
I'm writing some disposable Haskell scripts to solve some of the Project Euler problems.
I'm a beginner with Haskell and am having trouble figuring out some code. What
I'm using project Euler to teach myself Haskell, and I'm having some trouble reasoning
I'm having some trouble with regexes in haskell. Specifically: Prelude Text.Regex.Posix> 1 =~ \d

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.