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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:13:18+00:00 2026-05-27T19:13:18+00:00

Eventually I want to achieve a simple in memory message queue that stores messages

  • 0

Eventually I want to achieve a simple in memory message queue that stores messages as key-tuples e.g. {Dst-IP, Dst-Port {CreationTime, MessageList}} where all future messages for a specific Destinations IP address and Destination Port should be appended to MessageList.

I thought about invetigating Data.PSQueue (or maybe Data.Map). In the example above the Dst-IP, Dst-Port could be the key whilst CreationTime could be the priority. (I have no idea yet what the actual MessageList could be, but somehow I have to start and see).

Starting with PSQs I do not even get past the initial hurdle of types. Depending on how I modify the below snippet, I get various errors (either with the lookup function or with the print function) that all resemble

Couldn't match expected type `IO t0'
                with actual type `PSQ.PSQ k0 p0 -> Maybe p0'

or similar. How can I get past this initial problem?
Is there anything that fits my requirements better than Data.PSQueue?

{-# LANGUAGE OverloadedStrings #-}

import Control.Monad
import Control.Monad.State.Strict
import System.CPUTime

import qualified Data.PSQueue as PSQ
--import Language.Haskell.Pretty

main = do
     time <- getCPUTime
     let q = PSQ.singleton "msg" time
     r <- PSQ.lookup "msg"
     print (r)
  • 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-27T19:13:19+00:00Added an answer on May 27, 2026 at 7:13 pm

    You’ve written r <- PSQ.lookup "msg". <- is the syntax to extract a monadic value from within a block of do-notation. You should instead use let r = ..., the syntax to bind pure values.

    You also forgot the queue parameter itself. This is what the error message is telling you: the right-hand side of <- has to be of type IO a for some a, but instead it’s a function from a PSQ k p to the result of a lookup (Maybe p).

    After those two fixes, the corrected line is let r = PSQ.lookup "msg" q.

    Perhaps what you instead want is a State monad with a PSQ as the state; e.g. StateT PSQ IO. This would let you rewrite your snippet as follows:

    main :: IO ()
    main = flip runStateT PSQ.empty $ do
      time <- liftIO getCPUTime
      modify $ PSQ.insert "msg" time
      r <- gets $ PSQ.lookup "msg"
      liftIO . print $ r
    

    If you’re intending to write a concurrent program, the best solution is probably an MVar or TVar containing a PSQ instead.

    You might also be interested in the fingertree-psqueue package, an implementation of priority search queues based on finger trees. I haven’t used it or the PSQueue package you’re considering, but it seems to be more actively maintained.

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

Sidebar

Related Questions

The .NET garbage collector will eventually free up memory, but what if you want
We are working on a Qt application, that we eventually want to move the
I'm working on a haskell web app using yesod that I eventually want to
we've got an existing webapplication written in magic. But now we eventually want to
say I want to scaffold generate university but university should eventually be related to
I have a UIView that will eventually contain about 2 screens worth of information.
I am looking for an eventually consistent key value data store and i decided
I want to build an iOS application that recognizes patterns in a cup of
I've just started playing with T4, as I eventually want to use it to
I created a minuscule WCF service as a proof of concept. I eventually want

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.