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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:38:40+00:00 2026-06-18T09:38:40+00:00

Possible Duplicate: Outputting Haskell GHCi command results to a txt file I am new

  • 0

Possible Duplicate:
Outputting Haskell GHCi command results to a txt file

I am new to Haskell and I am trying to redirect test cases output results to a text file. The way it is set up now, is a AddAllTestCases.hs contains all the test cases I need to run in order to test a function I created. I run the test cases on GHCi by loading AddAllTestCases.hs and then simply typing main and hitting enter. That causes test case output results to print inside the GHCi perfectly.

Because there hundreds of test cases, I need to redirect output results to text file.

Attempt #1:

writeFile "myoutput.txt" $ show $ main

I get the following error:

No instance for (Show(IO())) arising from a use of show

Attempt #2 in CMD (trying to create an executable, then outputting executable results to text file):

ghc --make AddAllTests.hs -o testResults.exe

Which gives me the following error:

Warning: output was redirected with -o, but no output will be generated because there is no Min module

This is weird because when I am using GHCi (attempt #1) and I type in main it executes everything perfectly, which I would assume, implies that there is a main module?

I greatly appreciate any help with redirecting test case results to a text file.

Many thanks in advance!

  • 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-18T09:38:41+00:00Added an answer on June 18, 2026 at 9:38 am

    You need a Main module (and a main action) to produce an executable. You can rename your module to Main, or you can specify the module to be considered Main on the command line,

    ghc --make -main-is AddAllTests AddAllTests.hs -o testResults.exe
    

    to produce an executable without a module named Main.

    A method without compiling would be

    ghc AddAllTests.hs -e "main" > testResults.txt
    

    Another method would be to have a file in which you just list all test cases,

    3 + 2 :: Rational
    reverse "foobar"
    :q
    

    and run ghci with redirected in- and output

    ghci < testCases > testResults.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: putting print_r results in variable I'm throwing an exception and trying to
Possible Duplicate: outputting values from database into html table PHP I am trying to
Possible Duplicate: Can colorized output be captured via shell redirect? setup In this case
Possible Duplicate: Python : how to append new elements in a list of list?
Possible Duplicate: Why does my cout output not appear immediately? I have a very
Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: nth-child for every two table rows I'm trying to work my way
Possible Duplicate: How to efficiently write to file from SQL datareader in c#? I
Possible Duplicate: How to create an array from a CSV file using PHP and

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.