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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:18:38+00:00 2026-05-20T10:18:38+00:00

Haskell doesn’t feature explicit memory management, and all objects are passed by value, so

  • 0

Haskell doesn’t feature explicit memory management, and all objects are passed by value, so there’s no obvious reference counting or garbage collection either. How does a Haskell compiler typically decide whether to generate code that allocates on the stack versus code that allocates on the heap for a given variable? Will it consistently heap or stack allocate the same variables across different call sites for the same function? And when it allocates, how does it decide when to free memory? Are stack allocations and deallocations still performed in the same function entrance/exit pattern as in C?

  • 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-20T10:18:39+00:00Added an answer on May 20, 2026 at 10:18 am

    When you call a function like this

    f 42 (g x y)
    

    then the runtime behaviour is something like the following:

    p1 = malloc(2 * sizeof(Word))
    p1[0] = &Tag_for_Int
    p1[1] = 42
    p2 = malloc(3 * sizeof(Word))
    p2[0] = &Code_for_g_x_y
    p2[1] = x
    p2[2] = y
    f(p1, p2)
    

    That is, arguments are usually passed as pointers to objects on the heap like in Java, but unlike Java these objects may represent suspended computations, a.k.a. thunks, such as (g x y/p2) in our example. Without optimisations, this execution model is quite inefficient, but there are ways to avoid many of these overheads.

    1. GHC does a lot of inlining and unboxing. Inlining removes the function call overhead and often enables further optimisations. Unboxing means changing the calling convention, in the example above we could pass 42 directly instead of creating the heap object p1.

    2. Strictness analysis finds out whether an argument is guaranteed to be evaluated. In that case, we don’t need to create a thunk, but evaluate the expression fully and then pass the final result as an argument.

    3. Small objects (currently only 8bit Chars and Ints) are cached. That is, instead of allocating a new pointer for each object, a pointer to the cached object is returned. Even though the object is initially allocated on the heap, the garbage collector will de-duplicate them later (only small Ints and Chars). Since objects are immutable this is safe.

    4. Limited escape analysis. For local functions some arguments may be passed on the stack, because they are known to be dead code by the time the outer function returns.

    Edit: For (much) more information see “Implementing Lazy Functional Languages on Stock Hardware: The Spineless Tagless G-machine”. This paper uses “push/enter” as the calling convention. Newer versions of GHC use the “eval/apply” calling convention. For a discussion of the trade-offs and reasons for that switch see “How to make a fast curry: push/enter vs eval/apply”

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

Sidebar

Related Questions

So I'm totally new to Haskell, hope it doesn't show too much. By any
Haskell provides the feature something like f = f1 . f2 How can I
In Haskell, lifted type products mean that there's a semantic difference between (a,b,c) and
C++ being a value oriented language doesn't seem to support OO (and thus sub-typing
I've frequently heard claims that Haskell doesn't have variables; in particular, this answer claims
Is there a way to set argv[0] in a Haskell program (say, one compiled
I wonder that there is no Haskell TextMate Bundle. Macromates.com says that there was
This should be easy for Haskell pros.. I've got a Maybe value, > let
I'm trying to write 'fizzbuzz' in haskell using list comprehensions. Why doesn't the following
In Haskell there are two functions that allow one to perform an operation 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.