Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GHCi instructions from the command line

In the shell you can string commands together, separated by a semicolon:

cd ../haskell; rm ./foo; ghc foo.hs; cd ../original_directory

It would be great if you could do a similar thing for command-line arguments for ghci, e.g.

ghci Foo.hs; a <- getFoo; print a

Is this possible?

like image 422
amindfv Avatar asked Dec 26 '22 19:12

amindfv


1 Answers

You can use ghc -e for this:

sorghum:~/programming% cat test.hs
getFoo = getLine
sorghum:~/programming% ghc test.hs -e 'do { a <- getFoo; print a }'
oenuth
"oenuth"
like image 93
Daniel Wagner Avatar answered Jan 10 '23 14:01

Daniel Wagner