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

  • Home
  • SEARCH
  • 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 7644941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:48:43+00:00 2026-05-31T09:48:43+00:00

So I am working on Problem 31 . I have written the following function

  • 0

So I am working on Problem 31.

I have written the following function in hopes to determine if a number is a prime:

isPrime :: Integer -> Bool

isPrime x = prime x 2
            where
            prime :: Integer -> Integer -> Bool
            prime x y | ((y*y) < x) and ((x `mod` y) /= 0) = prime x (y+1)
                      | ((y*y) >= x) = True
                      | otherwise = False

My logic was make an isPrime function, and have a function within isPrime called prime to store 2 parameters, the number I want to check to see if it is prime (x) and an iterator to check all the numbers below sqrt of x and see if they divide x. prime has 3 guards:

| ((y*y) < x) and ((x `mod` y) == 0) = prime x (y+1)

This line is supposed to say: is the number I passed less than the square root of x (((y*y) < x)) and if it is check if x is divisible by y (((xmody) /= 0)), if it isn’t I use recursion and increment y to check again with a higher number.

This line:

| ((y*y) >= x) = True

Is supposed to be like if all the numbers below the square root don’t divide x in anyway, x must be prime.

Finally, this line:

| otherwise = False

means that a number somewhere along the line a number divided x so it is not prime.

I thought the code I wrote made sense, I know it isn’t the most efficient, considering I could just check primes below sqrt x and not all the numbers below sqrt x, but anyways, I am having problems with this statement:

((y*y) < x)

GHCi says:

The function `(y * y) < x' is applied to two arguments, but its type `Bool' has none

I thought that the < was supposed to take in two arguments and return a Bool, the error message doesn’t really make sense to me. Can you help me figure out what I am doing wrong? Thanks.

Quick edit now that I got it to run, this line:

| ((y*y) >= x) = True

should be:

| ((y*y) > x) = True
  • 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-05-31T09:48:45+00:00Added an answer on May 31, 2026 at 9:48 am

    To explain what’s happening here… the problem isn’t with <, it’s with the whole expression:

    ((y*y) < x) and ((x `mod` y) /= 0)
    

    What you’re missing is the backticks around and:

    ((y*y) < x) `and` ((x `mod` y) /= 0)
    

    When you use a function infix like that, if it isn’t an operator (i.e. made of symbols, like ++), then you need to surround it with backticks.

    Alternately, you can use it non-infix as a function, like:

    and ((y*y) < x) ((x `mod` y) /= 0)
    

    Now to explain the error message. What the compiler is saying is that you’re trying to use the expression ((y*y) < x) as a function. Since function application in Haskell doesn’t use brackets, anything like f x y is a function f applied to two arguments x and y.

    Since you forgot to put backticks around the and, Haskell interprets ((y*y) < x) and ((x `mod` y) /= 0) as you trying to apply the function ((y*y) < x) to the arguments and and ((x `mod` y) /= 0). Of course, this doesn’t work, because ((y*y) < x) returns Bool, which isn’t a function, so it complains with “The function (y * y) < x is applied to two arguments, but its type Bool has none”. Bool isn’t a function type, and so it has no arguments.

    …

    Of course, the other error you have now is that it should be && not and – and has type [Bool] -> Bool.

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

Sidebar

Related Questions

I working on project and have problem with threading and update of UI. I
I have a strange problem working with HTML,CSS in different browsers: Firefox 3.6 and
I'm working with oscommerce and i have problem with Paypal ipn When someone makes
I have been working on this problem for 2 days now and it's an
I have been working on this problem for a while now. I am trying
i have a problem, i'm working on a gallery php script and need help,
I have a problem with my CSS on a website I'm working on .
i have a problem. I am working on a chatting application. I want to
I am working on a problem and got stuck at a wall I have
I have a problem but first i want to know if im working on

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.