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

  • Home
  • SEARCH
  • 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 9226893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:56:14+00:00 2026-06-18T04:56:14+00:00

I have a Data.Sequence which I need to iterate over. The problem is that

  • 0

I have a Data.Sequence which I need to iterate over. The problem is that its stateful, and the sequence may grow as a result of said iteration.

data Chart = Chart {
       charts :: M.Map Int (Seq.Seq RState), --map from position to list of chart states
       ...
} deriving (Show)


processChartSeq :: Int -> Int  -> State Chart ()
processChartSeq chtIndx stIndx = do s <- get
                                    let seq = fromJust $ M.lookup chtIndx (charts s)
                                        rstate = Seq.index seq  stIndx
                                    processState rstate
                                    when (stIndx < Seq.length seq) (processChartSeq chtIndx (stIndx+1))

So I’m doing this with explicit recursion, but it seems clunky. Furthermore, it seems like a common thing to do. What common monadic control structure did I re-invent, badly?

  • 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-18T04:56:16+00:00Added an answer on June 18, 2026 at 4:56 am

    To answer the initial question, you “reinvented” the state monad within the state monad itself! You could move the stuff you’re explicitly threading into your state to avoid passing it directly. On the other hand, for simple things like this, I have no problem passing things around explicitly, and often find it cleaner.

    Finally, as Daniel Wagner notes, you should be pushing and popping from the top as much as possible, for the sake of efficiency.

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

Sidebar

Related Questions

Given a sequence of data (it may have duplicates), a fixed-sized moving window, move
I have data from two different sources that I need to combine. Some data
I'm writing some C++ code that will have to send data over TCP/IP. I
I have a long sequence of kernels I need to run on some data
I have a sequence of x, y and z -coordinates, which I need to
I have a very long string containing DNA sequence data, which is usually about
i have a project in c++03 that have a problem with data structure: i
I have data from travel diaries which has been read in from a csv
I have data-segment attribute in my body tag that is changed by a slider.
I have devices. Each one sends data to (server IP-address) over a particular port

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.