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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:12:16+00:00 2026-06-01T05:12:16+00:00

I was trying to write a function to get all subsequences of a list

  • 0

I was trying to write a function to get all subsequences of a list that are of size n, but I’m not sure how to go about it.

I was thinking that I could probably use the built-in Data.List.subsequences and just filter out the lists that are not of size n, but it seems like a rather roundabout and inefficient way of doing it, and I’d rather not do that if I can avoid it, so I’m wondering if you have any ideas?

I want it to be something like this type

subseqofsize :: Int -> [a] -> [[a]]

For further clarification, here’s an example of what I’m looking for:

subseqofsize 2 [1,2,3,3]
[[1,2],[1,3],[2,3],[1,3],[2,3],[3,3]]

Also, I don’t care about the order of anything.

  • 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-01T05:12:17+00:00Added an answer on June 1, 2026 at 5:12 am

    I’m assuming that this is homework, or that you are otherwise doing this as an exercise to learn, so I’ll give you an outline of what the solution looks like instead of spoon-feeding you the correct answer.

    Anyway, this is a recursion question.

    There are two base cases:

    sublistofsize 0 _        = ...
    sublistofsize _ []       = ...
    

    Then there are two recursive steps:

    sublistofsize n (x : xs) = sublistsThatStartWithX ++ sublistsThatDon'tStartWithX
      where sublistsThatStartWithX = ...
            sublistsThatDon'tStartWithX = ...
    

    Remember that the definitions of the base cases need to work appropriately with the definitions in the recursive cases. Think carefully: don’t just assume that the base cases both result in an empty list.

    Does this help?

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

Sidebar

Related Questions

I am trying to write a function to get a list of offers (their
I'm trying to write a recursive function that would get some string, as well
I am trying write a function that generates simulated data but if the simulated
I am trying to write a general function in F# that would return all
I am trying to write a function in Python 3 that will write all
I am trying to write a scheme function that takes a list of the
I'm trying to write a function in assembly (but lets assume language agnostic for
I'm trying to write a function that accepts a certain type or any of
I'm trying to write a function that plots a ggplot facet_wrap plot over multiple
I have been at this all day, trying to write a recursive function in

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.