Saturday 15 March 2014

haskell - Can runhaskell pick up options from .ghci? -



haskell - Can runhaskell pick up options from .ghci? -

many people include .ghci files in haskell projects include needed options load modules ghci. here's example:

:set -isrc -itest -iexamples -packagehspec2

however when trying run file containing main through runhaskell 1 has repeat these options, e.g.:

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

is there way allow runhaskell pick options .ghci file?

i don't know of way create runhaskell work. pipe "main" ghci:

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

if want pass command-line arguments, works too:

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

or can wrap in script:

#!/usr/bin/env runhaskell >import system.io >import system.environment >import system.exit >import system.process > >main :: io () >main = > 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

which can used so:

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

haskell ghc ghci runhaskell

No comments:

Post a Comment