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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:10:57+00:00 2026-05-31T12:10:57+00:00

Imagine you need to fold over a sequence, and want to know also the

  • 0

Imagine you need to fold over a sequence, and want to know also the intermediate values at several points along the range. This is what I’ve used for this:

[a,b,c] = map fst . tail $ chain [g i, g j, g k] (zero, sequence)

g :: Integer -> (a,b) -> (a,b)

chain (f:fs) x = x : chain fs (f x)
chain [] x = [x]

The function g consumes a specified portion of an input sequence (of length i, j, etc.), starting with some initial value and producing results of the same type, to be fed into the next invocation. Consuming the sequence several times for different lengths starting over from the start and same initial value would be inefficient, both time and space-wise of course.

So on the one hand we fold over this sequence of integers – interim points on the sequence; on the other hand we iterate this function, g. What is it? Am I missing something basic here? Can this be somehow expressed with the regular repertoire of folds, etc.?

EDIT:  Resolved:  the above is simply

[a,b,c] = map fst . tail $ scanl (flip g) (zero, sequence) [i, j, k] 

interesting how a modifiable iteration actually is folding over the list of modifiers.

  • 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-31T12:10:58+00:00Added an answer on May 31, 2026 at 12:10 pm

    Try scanl: http://www.haskell.org/hoogle/?hoogle=scanl

    scanl is similar to foldl, but returns a list of successive reduced
    values from the left:

    scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]
    

    Note that

    last (scanl f z xs) == foldl f z xs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need a timer that works like this : imagine somebody have a limit
To solve this, I can imagine I need to use PRISM or a datatemplate
So I imagine that I need a regex statement to do this but I
Imagine a matrix : a = 4 2 8 9 I need to repeat
Imagine the following: you read in a string with scanf() but you only need
imagine this html on a page <div id=hpl_content_wrap> <p class=foobar>this is one word and
Imagine I want to draw a pyramid made of triangles. -Should I create a
Imagine we need to pass a a number structured objects to the web application
I imagine I need to remove chars 0-31 and 127. Is there a function
I need to instantiate a new view on a command Imagine I have a

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.