Redirecting Haskell GHCi output to text file [duplicate]



<strong>Possible Duplicate:</strong><br /><a href="https://stackoverflow.com/questions/14595934/outputting-haskell-ghci-command-results-to-a-txt-file" rel="nofollow">Outputting Haskell GHCi command results to a txt file</a>


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!


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


  • How the game will search for other online users and will display the list of all users?
  • Matlab: “grouping mean”
  • MS Access query with dynamic from statements
  • mysqli_result::free increase php memory usage
  • Installing MEAN Stack: npm -v module.js: 338 throw err; Error: Cannot find module './cache/cach
  • Cannot debug project after upgrading to Service Fabric SDK v2.3.301
  • CouchDB views erroring out
  • How to make a npm command, that executes two commands in the console (one after another)?
  • In VIm, how to remove all lines that are duplicate somewhere?
  • IE readonly textarea problem
  • Mockery and Laravel constructor injection
  • Generic/Unknown HTTP Error with response code 0 using UnityWebRequest
  • Efficient User-Agent Regex to find Safari in Python
  • (Tcl/Expect) clear screen after exit
  • Scanner nextInt() and hasNextInt() problems
  • jQuery: How to AJAXify WordPress Search?
  • Trying to get the char code of ENTER key
  • Query to find the duplicates between the name and number in table
  • WPF ICommand CanExecute(): RaiseCanExecuteChanged() or automatic handling via DispatchTimer?
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • Eloquent update method change created_at timestamp
  • Typescript - Unable to get 'import' statement to function
  • Javascript simulate pressing enter in input box
  • output of program is not same as passed argument
  • Javascript Callbacks with Object constructor
  • Running a C# exe file
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • How can I use Kendo UI with Razor?
  • How to make Safari send if-modified-since header?
  • align graphs with different xlab
  • Akka Routing: Reply's send to router ends up as dead letters
  • Return words with double consecutive letters
  • How to pass list parameters for each object using Spring MVC?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • unknown Exception android
  • JaxB to read class hierarchy
  • Checking variable from a different class in C#
  • Running Map reduces the dimensions of the matrices
  • Reading document lines to the user (python)
  • Python/Django TangoWithDjango Models and Databases