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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:46:58+00:00 2026-05-11T07:46:58+00:00

I’m trying to implement a transparent cache that can load a specific object when

  • 0

I’m trying to implement a transparent cache that can load a specific object when it’s not available, or return an already existing object indexed by (name).

I’ve tried running this:

loader' objs name = case findObj objs name of   Nothing →  (new_obj, loader' new_objs)   Just obj →  (obj, loader' objs)   where     new_objs = [(name, new_obj)] ++ objs     new_obj = readObj name loader = loader' [] 

but I’m getting a

 Occurs check: cannot construct the infinite type:   t = (ObjType, String -> t) 

which looks exactly like something I want 🙂

How can I fix the function so that it compiles?

Clarifications:

As requested, signatures (findObj either returns a known value found via a key, or Nothing, readObj creates a new obj for a key):

findObj :: [(String, ObjType)] -> String -> Maybe ObjType readObj :: String -> ObjType 

And yes – I need a cache, because the keys are filenames and I don’t want to read+parse the file each time some object is needed.

  • 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. 2026-05-11T07:46:59+00:00Added an answer on May 11, 2026 at 7:46 am

    Two thoughts (wild guesses?) it looks as if it is failing to produce the right type signature in the Just obj clause and/or from readObj name, and it might be interesting to try something like this:

    loader' :: [(String, ObjType)] -> String -> (ObjType, String -> ObjType) loader' objs name = case findObj objs name of   Nothing →  (new_obj, loader' new_objs) where     new_objs = [(name, new_obj)] ++ objs     new_obj = readObj name   Just obj →  (obj, loader' objs) loader = loader' [] 

    I’m not saying that that will fix it (but I suppose that it might); rather, I’m saying that it may transform the problem into one that makes more sense, or otherwise shed light on the situation.

    Edit:

    Applying Tom Lokhorst’s suggestion of naming the cache type leads us to this:

    type Cache = [(String, ObjType)] loader' :: Cache -> String -> (ObjType, ????) loader' objs name = case findObj objs name of   Nothing →  (new_obj, loader' new_objs) where     new_objs = [(name, new_obj)] ++ objs     new_obj = readObj name   Just obj →  (obj, loader' objs) loader = loader' [] 

    which makes it obvious what the problem is. The type of the second result of loader’ is a function that takes a string an produces a pair consisting of an ObjType and a function that takes a string an produces a pair consisting of an ObjType and a function that takes a string an produces a pair consisting of an ObjType and a function that takes a string an produces a pair consisting of an ObjType and … you get the picture.

    If you rewrite it like this:

    type Cache = [(String, ObjType)] loader' :: Cache -> String -> (ObjType, Cache) loader' objs name = case findObj objs name of   Nothing →  (new_obj, new_objs) where     new_objs = [(name, new_obj)] ++ objs     new_obj = readObj name   Just obj →  (obj, objs) 

    it should compile but you’ll have to change how you use it.

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

Sidebar

Ask A Question

Stats

  • Questions 194k
  • Answers 194k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've just found an answer here: Accessing the model from… May 12, 2026 at 6:44 pm
  • Editorial Team
    Editorial Team added an answer You can store your array in appDelegate class. Or I… May 12, 2026 at 6:44 pm
  • Editorial Team
    Editorial Team added an answer We discovered the simplest solution that requires minimal changes to… May 12, 2026 at 6:44 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.