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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:18:23+00:00 2026-06-08T13:18:23+00:00

I am creating a sequence as a [Integer] in Haskell. The mathematical definition of

  • 0

I am creating a sequence as a [Integer] in Haskell. The mathematical definition of the sequence is such that it repeats for some positive integers. In such a situation, I want to terminate the sequence and determine the length of the finite list.

My attempt at a solution is to first create an infinite list from the mathematical sequence. Then I want to filter the list for all elements until the first element repeats. The result should not include the repeating head of the list.

I have two questions/concerns here:

1) How do I match the head of the list to an element later in the list?
2) Is this an efficient method of solving my problem? (I will add more details about the exact sequence later if needed. For now I am looking for general comments.)

  • 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-08T13:18:24+00:00Added an answer on June 8, 2026 at 1:18 pm

    The algorithm that you described can simply be implemented like this:

    findPeriodic :: Eq a => [a] -> [a]
    findPeriodic [] = error "there are no periodic sequences in the empty list"
    findPeriodic (x : xs) = x : takeWhile (/= x) xs
    

    It does exactly what you describe: it takes the head of some list, and collects the part of the list up until that head element appears again in the list. So, for example:

    list = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, ...]
    findPeriodic list => [1, 2, 3, 4, 5]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Has anyone got any example code for creating a unique number sequence to be
I'm creating a thread in android for a time consuming operation. I want the
I've inherited the task of creating a schema for some XML which already exists
I am creating a simple splash page with the following sequence: Fade in elements
Is there a way to creating an observable from a sequence in F#? The
I am creating a page that allows users access to a certain section of
I am creating a page that allows users access to a certain section of
I'm working on creating a for-loop that calls a javascript effect and applies it
I stuck into creating an XSD schema allowing only next sequence of elements: <root>

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.