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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:00:53+00:00 2026-05-25T20:00:53+00:00

Just out of curiosity, I made a simple script to check speed and memory

  • 0

Just out of curiosity, I made a simple script to check speed and memory efficiency of constructing a list in Haskell:

wasteMem :: Int -> [Int]
wasteMem 0 = [199]
wasteMem x = (12432483483467856487256348746328761:wasteMem (x-1))

main = do
    putStrLn("hello")
    putStrLn(show (wasteMem 10000000000000000000000000000000000))

The strange thing is, when I tried this, it didn’t run out of memory or stack space, it only prints [199], the same as running wasteMem 0. It doesn’t even print an error message… why? Entering this large number in ghci just prints the number, so I don’t think it’s a rounding or reading error.

  • 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-25T20:00:53+00:00Added an answer on May 25, 2026 at 8:00 pm

    Your program is using a number greater than maxBound :: Int32. This means it will behave differently on different platforms. For GHC x86_64 Int is 64 bits (32 bits otherwise, but the Haskell report only promises 29 bits). This means your absurdly large value (1×10^34) is represented as 4003012203950112768 for me and zero for you 32-bit folks:

    GHCI> 10000000000000000000000000000000000 :: Int
    4003012203950112768
    GHCI> 10000000000000000000000000000000000 :: Data.Int.Int32
    0
    

    This could be made platform independent by either using a fixed-size type (ex: from Data.Word or Data.Int) or using Integer.

    All that said, this is a poorly conceived test to begin with. Haskell is lazy, so the amount of memory consumed by wastedMem n for any value n is minimal – it’s just a thunk. Once you try to show this result it will grab elements off the list one at a time – first generating "[12432483483467856487256348746328761, and leaving the rest of the list as a thunk. The first value can be garbage collected before the second value is even considered (a constant-space program).

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

Sidebar

Related Questions

Just out of curiosity I decided to write a simple tool with the functionality
Just out of curiosity, why does calling IEnumerable.ToList() on an existing List not return
I'm fighting with memory leaks now. Just out of curiosity, when is mContext, the
Just out of curiosity, I'm trying to figure out which exactly is the right
Just out of curiosity, how does iostream access the input-output system. (I have a
Just out of curiosity, asking this Like the expression one below a = (condition)
This is mostly just out of curiosity, and is potentially a silly question. :)
Is there any way (just out of curiosity because I came across multiple same-value
I know this is a stupid question. But just out of curiosity, is there
Just out of curiosity I tried overriding a abstract method in base class, and

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.