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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:54:51+00:00 2026-06-05T07:54:51+00:00

How can I implement in haskell the following: I receive an input file from

  • 0

How can I implement in haskell the following:

  1. I receive an input file from the command line. This input file contains words separated with tabs, new-lines and spaces.
  2. I have to replace these elements (tabs, new-lines and spaces) with commas.
  3. And then write the result to a file called output.txt.

Any help is much appreciated. My haskell skills still developing.


So far I’ve got this code:

    processFile::String->String
    processFile [] =[]
    processFile input =input

    process :: String -> IO String
    process fileName = do
    text <- readFile fileName
    return (processFile text)

    main :: IO ()
    main = do
    n <- process "input.txt"
    print n

In processFile function I should process the text from the input file.

  • 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-05T07:54:52+00:00Added an answer on June 5, 2026 at 7:54 am

    You can use the getArgs function to read arguments on the command line. For example:

    import System.Environment (getArgs)
    
    main = do
      args <- getArgs
      case args of
        [arg] -> putStrLn $ "You gave me one arg: " ++ arg
        _     -> putStrLn $ "You gave me " ++ show (length args) ++ " arguments."
    

    You can use the readFile function to read a file.

    contents <- readFile "test.txt"
    putStrLn contents -- Prints the contents of the file
    

    You can use the writeFile function to write a file:

    writeFile "test2.txt" "Some file data\n" -- Writes the data to the file
    

    Tabs, newlines and spaces can be called whitespace, or word separators. The words function converts a string into a list of words.

    print $ words "some text with\nmany words"
    -- prints ["some", "text", "with", "many", "words"]
    

    The intersperse function inserts a separator between each element of a list:

    import Data.List (intersperse)
    
    main =
      print $ intersperse '.' ["some", "text", "with", "many", "words"]
      -- prints "some.text.with.many.words"
    

    You can also look at the intercalate function if you need longer separators.


    These are all of the tools that you need for your program, I think that you can figure out the rest. Good luck!

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

Sidebar

Related Questions

Can someone please tell me how I can implement the following line of pseudo-code.
Trying to implement, in Scala, the following Haskell function (from Learn You a Haskell...)
I want to implement the strict folding functions myself, from within Haskell: Is this
Can Clojure implement (g ∘ f) constructions like Haskell's g . f ? I'm
With WinGHCi, how can one implement the following code? soma :: Int -> Int
Hi i'm new to haskell and i'm trying to implement the following and I
I want to concatenate strings in Haskell and also integers from function like this:
When I open a file for reading in Haskell, I've found that I can't
I want to implement Maybe from Haskell in D, just for the hell of
I have the following (imperative) algorithm that I want to implement in Haskell: Given

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.