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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:55:07+00:00 2026-05-28T03:55:07+00:00

Say I want to write a function to decide whether a given integer number

  • 0

Say I want to write a function to decide whether a given integer number is prime, which type signature should I use?

  isPrime :: Int -> Bool

or

  isPrime :: (Integral a) => a -> Bool

What’s the difference? Is there a particular reason to choose one over the other?
If so, in which situations should I use the two respectively?

  • 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-28T03:55:08+00:00Added an answer on May 28, 2026 at 3:55 am

    The type Int -> Bool means that your function operates on values of type Int, which are size-limited integers (the maximum size being, I believe, machine-dependent).

    The type (Integral a) => a -> Bool means that your function operates on values of any type that has an instance of the Integral type class–i.e., types that behave like integers in a particular way. The main reason to chose this over a concrete type is to create a more general-purpose function.

    Generic forms using Integral tend to be most useful when you need to work with integer-like types in other contexts–a good example being places where the standard library fails to do so, e.g. functions like replicate :: Int -> a -> [a]. Code that operates on some specific integer-like type for its own purposes that wants to use that type with replicate therefore needs to convert to Int first, or import genericReplicate from Data.List.

    What you might want to consider in your case is instead the type Integer, which represents integers of arbitrary size. Since your main goal is the calculation, there’s less value to supporting arbitrary integral types.

    If memory serves me, the only instances of Integral in the standard library are Int and Integer anyhow. (EDIT: As hammar reminds me in the comments, there are also instances for fixed-size types in Data.Int and Data.Word. There are also foreign types like CInt but I was disregarding those intentionally.)

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

Sidebar

Related Questions

Let's say you want to write a function which gets passed an opaque handle
Let's say I want to write a function that does the following: Given a
Let's say I want to write a function that validates an email address with
How should I write error reporting modules in PHP? Say, I want to write
I want to write a global function for my whole project to use in
Let's say I want to have a function which reads data from the SerialPort
I want to write a program that calculates a given math function (by the
I want to write a program that checks if a function, say f halts
Let's say I want to write a regular expression to change all <abc> ,
So, let's say I want to write a class that operates on different kinds

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.