2014-10-31 18 views
6

Molte persone includono i file .ghci nei loro progetti haskell per includere le opzioni necessarie per caricare i moduli in ghci. Ecco un esempio:Can runhaskell accetta opzioni da .ghci?

:set -isrc -itest -iexamples -packagehspec2 

Tuttavia quando si tenta di eseguire un file contenente main attraverso runhaskell si deve ripetere tutte queste opzioni, come ad esempio:

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

C'è un buon modo per far runhaskell sollevare il opzioni dal file .ghci?

risposta

4

Non so in che modo eseguire il lavoro runhaskell. Quello che faccio è solo tubo "main" a ghci:

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

Se si vuole passare argomenti della riga di comando, che funziona anche:

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

Oppure si può avvolgerlo in uno 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 

che può essere utilizzato in questo modo:

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