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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:07:19+00:00 2026-05-24T16:07:19+00:00

I am running ghci from Terminal. In my source file, I defined factorial ::

  • 0

I am running ghci from Terminal.

In my source file, I defined

factorial :: Int -> Int
factorial n = product [1 .. n]

When I run this, I get the result

factorial 13 = 1932053504

product [1 .. 13] = 6227020800

For any number less than 13, the result is correct. However, for any number greater than or equal to 12, the two result do not agree.

Also if I define this function recursive :

factorial' :: Int -> Int
factorial' 0 = 1
factorial' (n + 1) = (n + 1) * factorial' n

I still get

factorial' 13 = 1932053504

If you understand what is occurring here, it would be very helpful. Thanks

  • 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-24T16:07:19+00:00Added an answer on May 24, 2026 at 4:07 pm

    According to the documentation for Int: A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]. Your factorial function is typed to use a an Int, which is overflowing. Now, if we check out the type of the second answer (from simply using product in GHCi), we see that it is of type Integer:

    Prelude> let a = product [1 .. 13]
    Prelude> :t a
    a :: Integer
    

    Integer is unbounded, and so is able to hold such a large number without overflowing.

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

Sidebar

Related Questions

Running this in python will result in a WindowsError stating it cannot find the
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
Running OS X Leopard an MacBook Pro from Jan. 2008. I used to run
Running this query in the SQLManagement studio returns a result set of 162 Rows
Running into a problem. I have a table defined to hold the values of
Running the static analyzer on this piece of code: - (id) readForeignPref { CFPropertyListRef
Running the following code, I get a StackOverflowError at the getPackage() line. How can
I've got the Haskell interpreter running in Emacs. With this I've got the typical
Running my play framework small app I get the following exception: ... Caused by:
Running into a problem where on certain servers we get an error that the

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.