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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:33:17+00:00 2026-06-04T06:33:17+00:00

I need to get an input until the empty line is entered and when

  • 0

I need to get an input until the empty line is entered and when the empty line is entered I need to print all first characters of each line (as one word).
Can somebody explain what should I write in the last line?

inp :: IO String
inp
   = do
      line <- getLine
      if null line
         then return ""
         else do
            lines <- inp
            return lines????
  • 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-04T06:33:18+00:00Added an answer on June 4, 2026 at 6:33 am

    I don’t want to spoil everything, but here are a few hints:

    1. String is actually just another name for [Char].
    2. You can construct a new list that’s just like an old one, but with a new element tacked onto the front with the (:) :: a -> [a] -> [a] function (and in particular, (:) :: Char -> String -> String). You can read this function aloud as “cons”. For example, 1:[2,3,4] is the same as [1,2,3,4], and 'a':"bcd" is the same as "abcd".
    3. When you’re certain a list isn’t empty, you can ask for its first element with the head :: [a] -> a function (and in particular, head :: String -> Char).
    4. As an alternative strategy, you might want to look into pattern matching instead of using null and if/then/else; this also eliminates the need for head, which is often a code smell.

    From a comment, you’ve also tried something like this as your last line:

    return head(lines) : []
    

    The main problem here is that return is not a keyword in Haskell, it’s just a plain old function. So if your argument is an expression, you need to parenthesize it (or use one of the various tricks for avoiding parentheses):

    return (head(lines) : [])
    return (head lines : [])
    return $ head lines : []
    return [head lines]
    let answer = head lines : [] in return answer
    

    etc. This should get you to where things typecheck and run; then you can get started correcting the bugs in the behavior of the code. =)

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

Sidebar

Related Questions

I need to get neighborhood element value. HTML is <div> <input type='hidden' value='12345'> <div
below is the chunk of XML i get as input and i need to
I need get all items these have no categories int? categoryId = null; var
Need to get the 10 word before and 10 words after for the given
I need to get all the objects whose id matches a specific pattern .
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I have two tables with a weak relation. I need get a text value
Need to get an div with overflow:hidden; not to wrap its children. I need
I need to get the size of a directory, recursively. I have to do
I need to get the Handler to the child Window of a certain application

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.