Can runhaskell select options from .ghci?

Many people include .ghci files in their haskell projects to include the necessary parameters for loading modules into ghci . Here is an example:

 :set -isrc -itest -iexamples -packagehspec2 

However, when trying to run a file containing main via runhaskell , you must repeat all these parameters, for example:

 runhaskell -isrc -itest -iexamples -packagehspec2 test/Spec.hs 

Is there a good way to let runhaskell select options from a .ghci file?

+6
source share
1 answer

I do not know how to make runhaskell work. What I am doing is just pipe "main" to ghci:

 $ echo main | ghci -v0 test/Spec.hs 

If you want to pass command line arguments, this also works:

 $ echo ':main -m "behaves correct"' | ghci -v0 test/Spec.hs 

Or you can wrap it in a script:

 #!/usr/bin/env runhaskell >import System.IO >import System.Environment >import System.Exit >import System.Process > >main :: IO () >main = do > source:args <- getArgs > (Just h, Nothing, Nothing, pid) <- createProcess (proc "ghci" ["-v0", source]) {std_in = CreatePipe} > hPutStr h ("import System.Environment\nSystem.Environment.withArgs " ++ show args ++ " main\n") > hClose h > waitForProcess pid >>= exitWith 

What can be used like this:

 $ ./run.lhs test/Spec.hs -m "behaves correct" 
+4
source

Source: https://habr.com/ru/post/977526/


All Articles