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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:33:18+00:00 2026-06-17T23:33:18+00:00

I am new to Haskell. I am having a really difficult time outputting command

  • 0

I am new to Haskell.

I am having a really difficult time outputting command results from GHCi to a file. I was wondering if someone can give me a simple explanation on how to do this? The examples I have found online so far seem over 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-06-17T23:33:19+00:00Added an answer on June 17, 2026 at 11:33 pm

    Let’s suppose you have a function mungeData and you do

     ghci> mungeData [1..5]
     [5,2,5,2,4,6,7,4,6,78,4,7,5,3,57,7,4,67,4,6,7,4,67,4]
    

    writeFile

    You can write this to file like this:

    ghci> writeFile "myoutput.txt" (show (mungeData [1..5])
    

    I’d be inclined to write

    ghci> writeFile "myoutput.txt" $ show $ mungeData [1..5]
    

    to get rid of a few brackets.

    Reading it back in

    You could get that back using

    ghci> fmap (read::String -> [Int]) $ readFile "myoutput.txt"
    

    One number per line

    You could output it a line per number like this:

    ghci> writeFile "myoutput'.txt" $ unlines.map show $ mungeData [1..5]
    

    which reads back in as

    ghci> fmap (map read.lines::String -> [Int]) $ readFile "myoutput'.txt"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really new to Haskell (Actually I saw Real World Haskell from O'Reilly
I'm kind of new to Haskell and I'm having a hard time understanding what
I'm new to haskell, and from time to time I bump into a problem
Hello I am new at Haskell and i'm having problems trying to get this
Still quite new to Haskell.. I want to read the contents of a file,
I'm very new to Haskell, so I'm having trouble absorbing all of the advanced
I'm new to haskell guys. I'm trying to write a gcd executable file. ghc
I'm fairly new to Haskell programming and I'm having trouble understanding why I'm receiving
I'm very new to Haskell, and I have a simple question. What function can
I am very new to Haskell. Could someone please explain why defining a list

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.