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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:32:46+00:00 2026-05-17T02:32:46+00:00

Im trying to create a list of strings using some recursion. Basically i want

  • 0

Im trying to create a list of strings using some recursion.

Basically i want to take a part of a string up to a certain point. Create a list from that and then process the rest of the string through recursion.

type DocName = FilePath
type Line = (Int,String)
type Document = [Line]

splitLines :: String -> Document
splitLines [] = []
splitLines str | length str == 0 = []
                             | otherwise = zip [0..(length listStr)] listStr
                                    where 
                                        listStr = [getLine] ++ splitLines getRest
                                        getLine = (takeWhile (/='\n') str)
                                        getRest =  (dropWhile (=='\n') (dropWhile (/='\n') str))

Thats what i got. But it just concats the strings back together since they are list of characters themselves. But i want to create a list of strings.

[“test”,”123″] if the input was “test\n123\n”

Thanks

  • 1 1 Answer
  • 2 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-17T02:32:47+00:00Added an answer on May 17, 2026 at 2:32 am

    If you try to compile your code, you’ll get an error message telling you that in the line

    listStr = [getLine] ++ splitLines getRest
    

    splitLines getRest has type Document, but it should have type [String]. This is easy enough to understand, since [getLine] is a list of strings (well a list of one string) and so it can only be concatenated with another list of strings, not a list of int-string-tuples.

    So to fix this we can use map to replace each int-string-tuple in the Document with only the string to get a list of strings, i.e.:

    listStr = [getLine] ++ map snd (splitLines getRest)
    

    After changing the line to the above your code will compile and run just fine.

    But it just concats the strings back together since they are list of characters themselves.

    I’m not sure why you think that.

    The reason your code did not compile was because of the type of splitLines as I explained above. Once you fix that error, the code behaves exactly as you want it to, returning a list of integer-string-tuples. At no point are strings concatenated.

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

Sidebar

Related Questions

What I'm trying to do is create a list of pure strings from a
I'm trying to create a list of tasks that I've read from some text
I am trying to create a list of a certain type. I want to
I am trying to create a list where I want users to enter data
I'm trying to create a list that some of the elements are defined and
i'm trying to deserialize a json string into a new list on C# using
I'm trying to list some strings in a Silverlight ListBox. I'm binding a vanilla
I'm trying to create a list of permutations of a list, such that, for
I'm trying to create UL list with images and descriptions. With 5 items in
I'm trying to create a list, with each <li> on one row. My problem

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.