runhaskell可以从.ghci获取选项吗?

sha*_*ahn 6 haskell ghc ghci runhaskell

许多人.ghci在其haskell项目中包含文件,以包含加载模块所需的选项ghci.这是一个例子:

:set -isrc -itest -iexamples -packagehspec2
Run Code Online (Sandbox Code Playgroud)

然而试图运行包含文件时,main通过runhaskell一个具有重复所有这些选项,如:

runhaskell -isrc -itest -iexamples -packagehspec2 test/Spec.hs
Run Code Online (Sandbox Code Playgroud)

有没有一种好方法可以runhaskell从.ghci文件中选择选项?

Sim*_*gel 4

我不知道有什么办法可以工作runhaskell。我所做的只是通过管道连接"main"到 ghci:

$ echo main | ghci -v0 test/Spec.hs
Run Code Online (Sandbox Code Playgroud)

如果您想传递命令行参数,也可以:

$ echo ':main -m "behaves correct"' | ghci -v0 test/Spec.hs
Run Code Online (Sandbox Code Playgroud)

或者您可以将其包装在脚本中:

#!/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
Run Code Online (Sandbox Code Playgroud)

可以像这样使用:

$ ./run.lhs test/Spec.hs -m "behaves correct"
Run Code Online (Sandbox Code Playgroud)