how to use ghci online- *h e l p*; it just scrolls fast? - haskell

when I tried to save the current ghci session using :save command I got the error
Prelude> :save
unknown command ':save'
use :? for help.
Prelude>
then when i type :? I got a ton of output that zoomed past the screen; how to read it one page at a time? is there anything like Unix less command there in ghci?

You could run GHCi from your shell and use shell redirection. This works for me on Windows:
echo :? | ghci > help.txt
more help.txt
I would expect this to also work on Unix, although I can't actually try it.

Related

Run a script (not a module) with ghc

Previously I used ghc version < 8 on Linux and when I had a script in a file, say file.hs, like
let x = "hello"
putStrLn x
double x=2*x
print $ double 2
double 3
then it was possible to run it and get the outputs in a terminal by doing
ghc -e ':script file.hs'
Now I'm using ghc 8.0.1 on Windows and this does not work anymore. Is there another way ?
I can get the outputs if I open GHCi and type :script file.hs. But I want these outputs in the terminal.
I don't know whether this is due to the upgrade of ghc or to the OS.
This works with double quotes:
ghc -e ":script file.hs"

To call a command in the ghci automatically when it starts [duplicate]

This question already has answers here:
How to configure GHCi to automatically import modules
(2 answers)
Closed 8 years ago.
Every time I run the ghci at first I call the :set prompt "ghci> " command manually. Can it happen automatically, instead of manually?
Define prompt in one of the config files
Simply put that GHCi command in the appropriate GHCi config file (e.g. in your user-level GHCi config file $HOME/.ghci on Unix systems):
:set prompt "ghci> "
Create that file if it doesn't already exist. Then you won't have to run the command manually every time after starting GHCi. More detail about GHCi config files is available here.
By the way, another fashionable prompt is λ>.
Don't forget to also customize prompt-cont (continuation prompt)
As pointed out by kqr in his comment, if you activate GHCi's multiline input mode (:set +m), you may also want to redefine, for consistency, prompt-cont—or prompt2 prior to v8.2.1, as pointed out in this comment—which corresponds to the continuation prompt. So your .ghci file should contain something like the following two lines:
:set prompt "λ> "
:set prompt-cont "λ| "
Otherwise, the default continuation prompt (Prelude|) will be used.
Test in GHCi
λ> :set +m
λ> let fact 0 = 1
λ| fact n = n * fact (n - 1)
λ|
(0.01 secs, 1547336 bytes)
λ> fact 5
120

latexpdf-esque functionality in haskell?

My haskell program produces .tex output using my own module.
I can't see my way around having to run 'pdflatex' everytime I want to see a result. I can hardly believe this cannot be done in a more direct manner;
Is there a way to have my code compile the .tex-file?
Is the System.Process package what you are looking for? You can use the function
system :: String -> IO ExitCode
to perform system calls.
$ touch tempfile.txt
$ ghci
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
>> import System.Process
>> system "ls"
tempfile.txt
ExitSuccess
Not particularly idiomatic, but it gets the job done.

Haskell ghci command line. return value overwrite last prompt

I installed ghci on Max OSX.
But everytime, the return value overwrite my last ghci prompt.
See below.
Falseghci>null[1,2,3]
Luke_ghci>
"False" over write my last line ghci prompt. (should be Luke_ghci)
So weird. How to solve it?
Thanks.
Copied from the above-linked message:
Aha! That led me to find it: I had TERM set to 'ansi'. ghci +
Haskeline works find if TERM is set to any of rxvt, vt52, vt100, vt102
or xterm. Don't know what in terminfo Haskeline is relying on, but
'ansi' doesn't have it!

Haskell line won't execute: do { n <- readLn ; print (n^2) }

I've been following a Learn Haskell in 10 Minutes tutorial. Everything was going well until I reached this line:
do { n <- readLn ; print (n^2) }
It won't execute in ghci, and in Leksah I get the following error.
Parse error: naked expression at top level
I've tried updating cabal and installing foo, but the problem continues.
Your help would be greatly appreciated.
I'm using Ubuntu 11.10.
It's not freezing, it's waiting for input. Try typing a number and pressing Enter.

Resources