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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:20:03+00:00 2026-05-27T22:20:03+00:00

Back Story : In an attempt to better understand Haskell and functional programming, I’ve

  • 0

Back Story: In an attempt to better understand Haskell and functional programming, I’ve given myself a few assignments. My first assignment is to make a program that can look through a data set (a set of numbers, words in a blog, etc), search for patterns or repetitions, group them, and report them.

Sounds easy enough. 🙂

Question: I’d like for the program to start by creating a list variable from the data in a text file. I’m familiar with the readFile function, but I was wondering if there was a more elegant way to input data.

For example, I’d like to allow the user to type something like this in the command line to load the program and the data set.

./haskellprogram textfile.txt

Is there a function that will allow this?

  • 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-27T22:20:04+00:00Added an answer on May 27, 2026 at 10:20 pm
    import System.Environment
    
    main :: IO ()
    main = do
      args <- getArgs
      -- args is a list of arguments
      if null args
        then putStrLn "usage: ./haskellprogram textfile.txt"
        else do contents <- readFile $ head args
                putStrLn $ doSomething contents
    
    doSomething :: String -> String
    doSomething = reverse
    

    That should be enough to get you started. Now replace reverse with something more valuable 🙂

    Speaking of parsing some input data, you might consider breaking your data into lines or words using respective functions from Prelude.

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

Sidebar

Related Questions

back story: I am designing a portfolio website for myself. on its home page,
The Back Story I have some decimal values which I am displaying as strings
Back Story: I was approached to write an app, but iOS isn't something that
Back story: I'm planning to implement a casual game to be deployed in a
quick back story-- I am working on ASP.Net based template editor that lets authors
Okay, so if you would like a back story, look at my previous question
Back story: Small-time iPhone developer, even have a (tiny) app on the App Store,
Back story i have a table that stores cached times, and currently has about
Back story: Long ago, before dinosaurs were around, there was a contractor that wrote
Basically the back story is that i've built a selecting of python scripts for

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.