Contents
How to start a GHCi session in Haskell?
Introduction to GHCi ¶ Let’s start with an example GHCi session. You can fire up GHCi with the command ghci: There may be a short pause while GHCi loads the prelude and standard libraries, after which the prompt is shown. As the banner says, you can type 😕 to see the list of commands available, and a half line description of each of them.
Can a GHCi expression be typed at the prompt?
Haskell expressions can be typed at the prompt: GHCi interprets the whole line as an expression to evaluate. The expression may not span several lines – as soon as you press enter, GHCi will attempt to evaluate it. In Haskell, a let expression is followed by in.
How is a let binding signalled in GHCi?
The expression may not span several lines – as soon as you press enter, GHCi will attempt to evaluate it. In Haskell, a let expression is followed by in. However, in GHCi, since the expression can also be interpreted in the IO monad, a let binding with no accompanying in statement can be signalled by an empty line, as in the above example.
When to give a module name or a filename in GHCi?
There is one exception to this general rule: when you load a program with :load, or specify it when you invoke ghci, you can give a filename rather than a module name. This filename is loaded if it exists, and it may contain any module you like.
Where do I save main.hs file in GHCi?
You can save Main.hs anywhere you like, but if you save it somewhere other than the current directory [3] then we will need to change to the right directory in GHCi: where ⟨dir⟩ is the directory (or folder) in which you saved Main.hs. To load a Haskell source file into GHCi, use the :load command:
How does GHC show the number of modules loaded?
Typically GHCi will show only the number of modules that it loaded after a :load command. With this flag, GHC will also list the loaded modules’ names. This was the default behavior prior to GHC 8.2.1 and can be useful for some tooling users.