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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:16:16+00:00 2026-05-28T11:16:16+00:00

I read this answer which made it sound like when a shared value is

  • 0

I read this answer which made it sound like when a shared value is evaluated, it is only evaluated once and then the result is stored. For example:

x = 2 + 2
y = 2 + x
z = 3 + x

Here, x is evaluated once and then stored as 4, and it is never evaluated again? At least that was my assumption. My code has a value that gets re-calculated every time it is referenced. It is a pure value. When would this happen, and how can I force Haskell to remember the value once it is calculated?

Example:

x = [1, 1, 2]
count = fst $ getCounts x

Here, count gets evaluated every time it is referenced.

  • 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-28T11:16:17+00:00Added an answer on May 28, 2026 at 11:16 am

    As Daniel Wagner points out, the most likely scenario here is that count is not given an explicit type signature, but you’ve turned the monomorphism restriction off (e.g. with the NoMonomorphismRestriction language extension). This means that count has a type like

    count :: (Num a) => a
    

    This means that GHC treats count like a function (specifically, from the Num typeclass dictionary for any type a, to an a), and so the results are not shared, meaning its value is recomputed on every use.

    The best solution is to give count an explicit type signature, e.g.

    count :: Int
    

    You should probably do the same for x, too (and, for that matter, all the other top-level definitions in your program).

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

Sidebar

Related Questions

I read this answer which tells Mockery is an anti-pattern of TDD. But wait!
I read this answer and its comments and I'm curious: Are there any reasons
I read this answer on SO: Because the recursive mutex has a sense of
Well I was reading this post and then I came across a code which
I read this answer, and it just confused me: TicTacToe AI Making Incorrect Decisions
In the answers to this question , we read that function f() {} defines
I've read all the answers on to this questions and none of the solutions
This is a question you can read everywhere on the web with various answers:
I have read some posts about this topic and the answers are comet, reverse
I've read through many of the questions on SO about this, but many answers

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.