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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:59:30+00:00 2026-05-21T22:59:30+00:00

In a pure functional language with lazy semantics (such as Haskell), results of computations

  • 0

In a pure functional language with lazy semantics (such as Haskell), results of computations are memoized so that further evaluations of a function with the same inputs do not recompute the value but get it directly from the cache of memoized values.

I am wondering if these memoized values get recycled at some point in time?

  1. If so, it means that the memoized values must be recomputed at a later time, and the benefits of memoization are not so exiting IMHO.
  2. If not, then ok, this is clever to cache everything… but does it mean that a program – if run for a sufficient long period of time – will
    always consume more and more memory ?

Imagine a program performing intensive numerical analysis: for example to find roots of a list of hundred of thousands mathematical functions using a dichotomy algorithm.

Every time the program evaluates a mathematical function with a specific Real Number, the result will be memoized. But there is only a really small probability
that exactly the same Real Number will appear again during the algorithm, leading to memory leakage (or at least, really bad usage).

My idea is that maybe memoized values are simply “scoped” to something in the program (for example to the current continuation, call stack, etc.), but I was unable to find something practical on the subject.

I admit I don’t have looked deeply at the Haskell compiler implementation (lazy?), but please, could someone explain to me how it works in practice?


EDIT: Ok, I understand my mistake from the first few answers: Pure semantics implies Referential Transparency which in turn does not imply automatic Memoization, but just guarantees that there will be no problem with it.

I think that a few articles on the web are misleading about this, because from a beginner’s point of view, it seems that the Referential Transparency property is so cool because it allows implicit memoization.

  • 1 1 Answer
  • 2 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-21T22:59:31+00:00Added an answer on May 21, 2026 at 10:59 pm

    Haskell does not automatically memoize function calls, precisely because this would quickly consume tons of memory. If you do memoziation yourself, you get to choose at what scope the function is memoized. For example, let’s say you have the fibonacci function defined like this:

    fib n = fibs !! n
        where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
    

    Here the memoization is only done within one call to fib, whereas if you leave fibs at the top level

    fib n = fibs !! n
    
    fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
    

    then the memoized list is kept until the garbage collector can determine that there are no more ways to reach fibs from any part of your program.

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

Sidebar

Related Questions

Haskell is a pure functional language, which means Haskell functions have no side affects.
Haskell has been called a pure functional language. What does pure mean in this
It's fairly obvious why a functional programming language that wants to be lazy needs
I am trying to learn pure functional programming language like Haskell as I am
I have a method that is a pure function and takes a while to
The unmanaged function(pure c++, if that matters): void fooC(float& result); I define the wrapper
I know that it's OK for a pure virtual function to have an implementation.
How does one go about doing doubly linked lists in a pure functional language?
As Erlang is an almost pure functional programming language, I'd imagine this was possible:
I've recently learned Haskell, and am trying to carry the pure functional style over

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.