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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:31:19+00:00 2026-06-18T10:31:19+00:00

In the Control.Proxy tutorial for the pipes-3.1.0 package, the author provides this function: cache

  • 0

In the Control.Proxy tutorial for the pipes-3.1.0 package, the author provides this function:

cache :: (Proxy p, Ord key) => key -> p key val key val IO r
cache = runIdentityK (loop M.empty) where
    loop _map key = case M.lookup key _map of
        Nothing -> do
            val  <- request key
            key2 <- respond val
            loop (M.insert key val _map) key2
        Just val -> do
            lift $ putStrLn "Used cache!"
            key2 <- respond val
            loop _map key2

Because I’d like to have a concurrent application caching requests, I have the following data type

newtype Cache k v = Cache (MVar (M.Map k v))

and now I want a new cache function with the signature

cache :: (Proxy p, Ord k) => Cache k v -> k -> p k v k v IO r
cache (Cache c) k = readMVar c >>= \m -> runIdentityK $ loop m k
    where loop m key = case M.lookup key m of
            Nothing -> do
                val <- request key
                respond val >>= loop (M.insert key val m)
            Just val -> respond val >>= loop m

however, this fails to typecheck since readMVar is in the IO monad, and runIdentityK is in the Proxy p => p k v k v IO r monad. Surely I can lift readMVar into this proxy monad since it’s a transformer over IO, but I cant find the right combinator.

  • 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-06-18T10:31:21+00:00Added an answer on June 18, 2026 at 10:31 am

    The solution was a simple lift. I had thought to use it before but apparently hadn’t tried hard enough. Here is a rough, type-checking version of my desired cache

    cache = runIdentityK . loop
        where loop (Cache c) key = lift (takeMVar c) >>= \m -> case M.lookup key m of
                Nothing -> do
                    val <- request key
                    lift . putMVar c $ M.insert key val m
                    respond val >>= loop (Cache c)
                Just val -> do
                   lift $ putMVar c m 
                   respond val >>= loop (Cache c)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The original code: this.control.addEventListener('click', $.proxy(function() { this.time.hashours = (this.duration() / 3600) >= 1.0; this.time.duration.text(getTime(this.duration(),
This question: Using Proxy with web browser control Told me to use InternetSetOption. How
I have a machine control system in Python that currently looks roughly like this
Is there a possibility of specifying a proxy for a WebBrowser control in a
The Cache-Control HTTP/1.1 header can specify max-age as well as whether the cache content
Can you please describe an example indicating difference between Public and Private Cache-Control in
I'm trying to use squid as a reverse cache proxy in front of a
How can you send control key combination to an element when using watir-webdriver? Currently
I know that it's possible to set up Privoxy and then control which proxy
TFS Proxy is designed to enable Team Foundation Server to mirror source control files

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.