Is it possible to combine ghci into a file and process it in bulk?For example,
test.hs
1+2
3*5
I would like to get the following output from ghci by entering the file
Prelude>1+2
3
Prelude > 3*5
15
Prelude >
We tried the following commands and the following in ghci interactive mode:l test.hs, but all of them received Parse error:naked expression at top level and did not get the same results as above.
ghcitest.hs
runhc test.hs
If you want the command to always run, write the command in the .ghci
file in the current directory and run ghci without any arguments to load it automatically.
If you want to separate files, you can create a file such as test.ghci
and run it with ghci-ghci-script test.ghci
.
These files are called ghciscripts and are not Haskell sources, so naturally loading will result in compilation errors.
If only the results are acceptable, there is :s
(:script
).
Prelude>:test.hs
3
15
Prelude >
© 2024 OneMinuteCode. All rights reserved.