Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aliases in Haskell/GHCI

Is it possible to set aliases in the ghci.conf file?

For example I have alias sbh='cd Desktop/Sandbox/Haskell' in bash.bashrc which lets me quickly jump to the specified folder. Is the same thing possible in ghci by putting an alias in the ghci.conf file?

I already have a few commands in ghci.conf but I would like to have multiple aliases set up to jump to folder locations without having to use :cd home/sandbox/foo/bar all of the time. I cant find anything on google so either its never been considered before or am just missing something very simple.

like image 927
Dave0504 Avatar asked Aug 19 '14 10:08

Dave0504


Video Answer


2 Answers

The :def command can do this:

:def sbh const $ return ":cd Desktop/Sandbox/Haskell"

As you can see it is a little more complicated than just giving a substitution string: It takes a Haskell function of type String -> IO String which the newly defined command applies to its argument string to calculate new commands to run.

Then in GHCI :sbh to invoke.

like image 144
Ørjan Johansen Avatar answered Oct 10 '22 06:10

Ørjan Johansen


GHCI macros should give you what you're looking for. See: https://www.haskell.org/ghc/docs/7.6.2/html/users_guide/ghci-commands.html as a reference.

Search for "macros" (or :def, which is the command to define macros). You can put these in the ghci.conf file.

For example (from the same URL indicated above):

Prelude> let mycd d = Directory.setCurrentDirectory d >> return "" Prelude> :def mycd mycd Prelude> :mycd ..

I hope this helps.

like image 39
fgv Avatar answered Oct 10 '22 06:10

fgv