Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to :reload and run :main as a single command in GHCi?

Tags:

haskell

ghc

ghci

Is there a way to chain :reload/:r along with :main as a single command in GHCi?

The goal here is to avoid typing both every time I change something in my other terminal, but to just type Enter.

like image 911
Jakub Arnold Avatar asked Jun 05 '14 01:06

Jakub Arnold


People also ask

How do I reload a Haskell file?

Basic Haskell Commands :quit (or :q) :load [filename] (or :l [filename]) :reload -- reload the current file set after you'ved edited it (or :r) :cd -- change to another directory.

How do I run a program in ghci?

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.

How do I load a module in Haskell?

The syntax for importing modules in a Haskell script is import <module name>. This must be done before defining any functions, so imports are usually done at the top of the file. One script can, of course, import several modules. Just put each import statement into a separate line.

How do you clear the command prompt in Haskell?

On Windows, use Ctrl + L for Haskell command prompt terminal. And, for GUI use Ctrl + S. Save this answer.


1 Answers

:cmd seems to accept string with multiple lines. Therefore you can do the following command.

:cmd return $ unlines [":reload",":main"]

also you can add following code to ~/.ghci

:def hoge const $ return $ unlines [":reload",":main"]

now you can execute :hoge in ghci

like image 89
ymonad Avatar answered Sep 24 '22 15:09

ymonad