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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:11:21+00:00 2026-05-27T21:11:21+00:00

I have the demonstrator code below that fails to compile with the error: Occurs

  • 0

I have the demonstrator code below that fails to compile with the error:

Occurs check: cannot construct the infinite type: p0 = Maybe p0
    Expected type: PSQ.PSQ (t1, t2, (t0, [a0])) (Maybe p0)
      Actual type: PSQ.PSQ (t1, t2, (t0, [a0])) p0
    In the third argument of `PSQ.insert', namely `q'
    In the expression: PSQ.insert test' time q

If I make the code from AppendMsg part of main it compiles. If a try to make it a separate function it fails with the strange maybe related error. I am not quite sure where the maybe type comes from. I have tried to resolve it with e.g. let time = Just (PSQ.lookup test time) but no joy. I have tried it without Data.Label/lenses but also no joy. Even a very simple function to insert the additional message gives the same error.

What could be wrong here?

import Data.Time
import Data.Time.Clock.POSIX
import qualified Data.PSQueue as PSQ
import Data.Maybe
import Data.Label
import Control.Category
import Prelude hiding ((.))

test = ("192.168.1.1", 3455, (1234566, msgs))
msgs = ["aaa", "bbbb", "ccccc"]

second2 = lens (\(a,b) -> b)   (\b (a,_) -> (a,b))
third3  = lens (\(a,b,c) -> c) (\c (a,b,_) -> (a,b,c))
messages = second2 . third3

append x = modify messages (x :)

newRq = do
      time <- getPOSIXTime
      let q = PSQ.singleton test time
      return q

appendMsg a q = do
      let time = PSQ.lookup test q
      let test' = append a test
      let q' = PSQ.insert test' time q
      let q = PSQ.delete test q' 
      return q

--insertNewRec a q = do 
--     time <- getPOSIXTime
--     let q' = PSQ.insert a time q
--     return q

main :: IO()
main = do
     q <- newRq
     let q' = appendMsg "first" q
     print (q')

Have revised appendMsg according to all comments/answers (see below). It now compiles but execution ends with <<loop>> :-(.

appendMsg :: String -> PSQ.PSQ (String, Integer, (Integer, [String])) POSIXTime -> PSQ.
PSQ (String, Integer, (Integer, [String])) POSIXTime 
appendMsg a q = q
      where 
       Just time = PSQ.lookup test q
       test2 = append a test
       q' = PSQ.insert test2 time q
       q = PSQ.delete test q' 
  • 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-27T21:11:22+00:00Added an answer on May 27, 2026 at 9:11 pm

    Apart from the dubious monadic type of appendMsg, instead of

    let time = Just (PSQ.lookup test time)
    

    (btw. I suppose the second ‘time’ is a typo and was actually a ‘q’), you should have tried

    let Just time = PSQ.lookup test q
    

    And I strongly recommend giving type signatures for your functions, that way GHC can give you much more helpful error messages since that way type errors are reported where they are made, and not where they cause type checking to fail.

    Edit: The reason for the <<loop>> in the revised code

    appendMsg :: String -> PSQ.PSQ (String, Integer, (Integer, [String])) POSIXTime
              -> PSQ.PSQ (String, Integer, (Integer, [String])) POSIXTime 
    appendMsg a q = q
      where 
       Just time = PSQ.lookup test q
       test2 = append a test
       q' = PSQ.insert test2 time q
       q = PSQ.delete test q'
    

    is the circular dependency of q and q' in the where clause. The bindings in a where clause (or a let) are recursive and can be arbitrarily ordered, so the qs in that all refer to the one bound in the last line, not the parameter – whoops. In the original code you had multiple lets, so the bindings were not (mutually) recursive and a binding let x = ... shadowed any previous binding of the identifier x.

    To break the <<loop>>, the easy and recommended fixes are

    • appendMsg a q = q'' and in the last line of the where clause q'' = PSQ.delete test q'
    • appendMsg a q = PSQ.delete test q' and remove the last line of the where clause

    You can also build a let-tower

    appendMsg a q =
        let Just time = ... in
        let test2 = ... in
        let q' = ... in
        let q = ... in q
    

    but I don’t recommend that.

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

Sidebar

Related Questions

I have just begun Rails 3. I have generated the below code using the
I have some data that is constrained below a 1:1 line. I would to
The following code demonstrates a weird problem I have in a Turbo C++ Explorer
Does anyone have sample code, or a tutorial which demonstrates how to use Grappa
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
Does MS have a sample enterprise application that demonstrates the use of different Enterprise
Over the last few days I have noted a few web sites that demonstrated
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
I have an ASP.NET application that accesses private key in a certificate in the

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.