I am new to Haskell and using a Windows PC. I am trying to set up my GHCi interface so that I can write my code in my text editor before executing it using the GHCi.
Currently, my GHCi reads
$ ghci GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude>
According to this site, I have to save my Haskell files to the current directory or specify some other directory in order to access them. This is what I don't know how to do.
My Questions:
Please explain starting from the line
Prelude>
as noted above so that I can follow along.
Note:
The example Haskell code given was
file name: Main.hs
main = print(fac(20))
fac 0 = 1
fac n = n * fac(n-1)
and in the GHCi
prelude> :load Main
Compiling Main ( Main.hs, interpreted )
Ok, modules loaded: Main.
*Main> fac 17
355687428096000
So I want to save Main.hs to a directory, specify this as the current directory in the GHCi, and then run the above code.
:cd -- change to another directory. :type [expr] -- give the type of an expression (or -- just :t) :set +t tell Haskell to print type information after evaluation.
If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt. The Haskell system now attentively awaits your input.
From the command line, enter "ghci" (or "ghci -W") followed by an optional filename to load. Note: We recommend using "ghci -W", which tells GHC to output useful warning messages in more situations. These warnings help to avoid common programming errors.
How do I set the current directory?
GHCi provides the :cd <dir>
command. You can get the list of all commands with :?
. If you omit the directory, you will change to your home again.
How do I get the GHCi to tell me what the path for current directory is so I can check what it is set at when I want to?
Funny enough, GHCi doesn't provide a command for this, but you can use Window's cd
command. In order to execute an external command, you need to use :!
, e.g. :! cd
.
ghci> :! cd C:\Users\Zeta ghci> :cd workspace ghci> :cd stackoverflow ghci> :! cd C:\Users\Zeta\workspace\stackoverflow ghci> :cd ghci> :!cd C:\Users\Zeta
well just answer is :cd
as @Zeta wroted
but futher more, for searching someone like me
:cd
:! cd
just like vim !
is of user's OS console:cd <DIR>
is almost equor :! cd <DIR>
:show paths
that shows somepaths, and there's current dicectoryPS> Searched some conf.d(~/.ghci/ghci.conf) like one but failed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With