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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:37:03+00:00 2026-06-10T22:37:03+00:00

Given a list :: [(Foo, Bar)] , I’d like to perform a scanl1 on

  • 0

Given a list :: [(Foo, Bar)], I’d like to perform a scanl1 on the Bars, but preserve their Foo “tags”.

I.e. I’d like a function with the type :: [(a, b)] -> ([b] -> [c]) -> [(a, c)], so that I can pass a curried scanl1 as the second argument.

I can write it recursively, but it feels like there’s a way to compose higher-order functions to do this.

Is this already possible with standard functions?

  • 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-10T22:37:04+00:00Added an answer on June 10, 2026 at 10:37 pm

    Instead of writing an unsatisfying higher order function, you could lift your combining function to thread the Foo tags through so you can still use scanl1 , which is what you mean.

    keeptags :: (Bar -> Bar -> Bar) -> (Foo,Bar) -> (Foo,Bar) -> (Foo,Bar)
    keeptags g (_,b) (a',b') = (a',g b b')
    

    Now you can use scanl1; take your original qux :: Bar -> Bar -> Bar and make

    scanQux :: [(Foo,Bar)] -> [(Foo,Bar)]
    scanQux = scanl1 (keeptags qux) 
    

    keeptags is simple and scanQux is crystal clear.

    For example, if

    type Foo = Char
    type Bar = Int
    
    qux = (+)
    

    then you get

    *Main> scanl1 qux [1..9]
    [1,3,6,10,15,21,28,36,45]
    
    *Main> zip "HELLO MUM" [1..9]
    [('H',1),('E',2),('L',3),('L',4),('O',5),(' ',6),('M',7),('U',8),('M',9)]
    
    *Main> scanQux $ zip "HELLO MUM" [1..9]
    [('H',1),('E',3),('L',6),('L',10),('O',15),(' ',21),('M',28),('U',36),('M',45)]
    

    as you had hoped.

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

Sidebar

Related Questions

I have a list like so <ul id=a> <li data-id=i1 data-pk-type=foo bar>sdfsf</li> <li data-id=i2
given this xml: <root> <list> <!-- foo's comment --> <item name=foo /> <item name=bar
Given a list ["foo", "bar", "baz"] and an item in the list "bar" ,
Given a simple zero based, numerically indexed array: var list = ['Foo', 'Bar', 'Baz'];
Given a list of tuples for parameter names and values e.g.: [(foo, 10), (bar,
Given a list like this: num = [1, 2, 3, 4, 5] There are
Given a list of elements like so: int[] ia = new int[] { -4,
Given the following dom structure I would like to transform an ordered list to
Given a starting List<Foo> , what is the most concise way to determine if
Given the following string, I'd like to match the elements of the list and

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.