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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:40:06+00:00 2026-05-30T18:40:06+00:00

I need to generate an infinite list of strings using numbers and letters. The

  • 0

I need to generate an infinite list of strings using numbers and letters. The first string should simply be “a”, then “b” through to “z”, then “0” through to “9”, then “aa”, “ab” etc.

I can easily generate the ones with one character, but then it gets more complicated.

  • 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-30T18:40:08+00:00Added an answer on May 30, 2026 at 6:40 pm

    So, suppose we already had this list of all possible strings:

     allStrings :: [String]
     allStrings = ...
    

    Given allStrings, how could we create another list of all possible strings?

     alsoAllStrings :: [String]
    

    Let’s look at each possible string as a single character prefix, and a string suffix

     alsoAllStrings = [ c : s 
    

    The string suffix is either the empty string or a member of the list of all possible strings.

                      | s <- "" : allStrings
    

    The single character prefix is in 'a' thru 'z' or '0' thru '9'.

                      , c <- ['a'..'z'] ++ ['0'..'9']
                      ]
    

    (this is using list comprehensions – we could also do the same using concatMap:

    alsoAllStrings = concatMap (\s -> map (:s) $ ['a'..'z'] ++ ['0'..'9']) $ "" : allStrings
    

    )

    Now let’s go back to the original question. How do we find allStrings?

    In most languages, we couldn’t – it’s an infinite list of strings, the program would never finish. But since Haskell is lazy, it’s cool with generating only as much of allStrings as we actually use.

    One surprising thing that this lets us do is we can define allStrings in terms of alsoAllStrings.

     allStrings = alsoAllStrings
    

    Or, more likely, in terms of itself.

     allStrings = [ c : s | s <- "" : allStrings, c <- ['a'..'z'] ++ ['0'..'9'] ]
    

    This is called corecursive data – data that is defined in terms of itself.
    Try it out in ghci:

     ghci> let allStrings = [ c : s | s <- "": allStrings, c <- ['a'..'z'] ++ ['0'..'9'] ]
     ghci> take 100 allStrings
     ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","aa","ba","ca","da","ea","fa","ga","ha","ia","ja","ka","la","ma","na","oa","pa","qa","ra","sa","ta","ua","va","wa","xa","ya","za","0a","1a","2a","3a","4a","5a","6a","7a","8a","9a","ab","bb","cb","db","eb","fb","gb","hb","ib","jb","kb","lb","mb","nb","ob","pb","qb","rb","sb","tb","ub","vb","wb","xb","yb","zb","0b","1b"]
    

    The reason it works (and doesn’t just loop infinitely) is that it defines part of itself before it uses itself. The first elements we include in allStrings are the single character extensions to the empty string "". So by the time we start iterating through the elements of allStrings to use as suffixes, the first couple elements allStrings are already defined and available. And the more suffixes we process, the more elements of allStrings are defined and available to use as suffixes.

    It’s very similar to a common haskellism of defining the fibonacci numbers corecursively:

     fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
    

    Don’t be surprised if corecursion takes a while to wrap your head around. It’s worth the effort to understand, though.

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

Sidebar

Related Questions

I need to generate an infinite stream of random integers, with numbers to be
I need to operate on two separate infinite list of numbers, but could not
I need to generate a controlled sequence of pseudo-random numbers, given an initial parameter.
I need to generate the following XML: <Learner xmlns=some.domain.api> <ActivationDate>1999-05-31T11:20:00</ActivationDate> <EmailAddress>String content</EmailAddress> <ExpirationDate>1999-05-31T11:20:00</ExpirationDate> <FederalId>String
I need to generate all permutation of a string with selecting some of the
Possible Duplicate: Creating a unique alphanumeric 10-character string I need to generate unique random
I need to generate unique record id for the given unique string. I tried
I need generate codes from this letters $a = array( 'B','C','D','F','G','H','J','K','L','M','N','O', 'P','Q','R','S','T','V','W','X','Y','Z','1','2', '3','4','5','6','7','8','9','0' );
Need to generate courses list and count all unanswered answered but unchecked Questions. My
Need to generate courses list and count all unanswered answered but unchecked Questions. Here's

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.