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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:24:31+00:00 2026-05-27T10:24:31+00:00

What do the thunks for the following value/expression/function look like in the Haskell heap?

  • 0

What do the thunks for the following value/expression/function look like in the Haskell heap?

val = 5                -- is `val` a pointer to a box containing 5?
add x y = x + y        
result = add 2 val     
main = print $ result

Would be nice to have a picture of how these are represented in Haskell, given its lazy evaluation mode.

  • 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-27T10:24:31+00:00Added an answer on May 27, 2026 at 10:24 am

    Official answer

    It’s none of your business. Strictly implementation detail of your compiler.

    Short answer

    Yes.

    Longer answer

    To the Haskell program itself, the answer is always yes, but the compiler can and will do things differently if it finds out that it can get away with it, for performance reasons.

    For example, for ”’add x y = x + y”’, a compiler might generate code that works with thunks for x and y and constructs a thunk as a result.
    But consider the following:

    foo :: Int -> Int -> Int
    foo x y = x * x + y * y
    

    Here, an optimizing compiler will generate code that first takes x and y out of their boxes, then does all the arithmetic, and then stores the result in a box.

    Advanced answer

    This paper describes how GHC switched from one way of implementing thunks to another that was actually both simpler and faster:
    http://research.microsoft.com/en-us/um/people/simonpj/papers/eval-apply/

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

Sidebar

Related Questions

I'd like to solve the following expression: for the following equation: How? Is there
I have the following regular expression in Ruby: \<name\>(.+)\<\/name\> Within in if statement, like
Getting the above error in following code. How to rectify it. Thanks. Please look
I get the following string expression provided: ChildObject.FullName ...where ChildObject is an instance property
I have the following XML (simplification): <?xml version=1.0 encoding=utf-8?> <TestCases> <TestCase> <Name>Test1</Name> <Result>Failed</Result> <Properties>
I am looking to substitute hash value with perl regular expression /e option. The
Take a gander at the following code. Basically, this is a function that gets
Given the following classes: public class Class1<TObject> { protected void MethodA<TType>(Expression<Func<TObject, TType>> property, ref
I have the following function that is extracting me distinct values based on the
I have a issue in SSRS when I use expression to use Round function

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.