Haskell / GHCI Aliases

Can I set aliases in the ghci.conf file?

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

I already have several commands in ghci.conf, but I would like to have several aliases configured to go to the folder without using :cd home/sandbox/foo/bar all the time. I can’t find anything on google, so either they never looked at it, or just missed something very simple.

+5
source share
3 answers

The :def command can do this:

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

As you can see, this is a bit more complicated than just giving a lookup string: it takes a function of type Haskell of type String -> IO String , which the new command applies to its argument string to compute new commands to run.

Then in GHCI :sbh to call.

+9
source

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

Find "macros" (or: def, which is the command for defining macros). You can put them in the ghci.conf file.

For example (from the same URL above):

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

Hope this helps.

+3
source

Perhaps not quite what you need, but in case the quick jump function is enough, try this as the first fix (called :sbh ):

 :def sbh (\arg -> return ("System.Directory.setCurrentDirectory \"Desktop/Sandbox/Haskell\"")) 

Your later solution may use the arg link, as in:

 :def sbh (\arg -> return ("System.Directory.setCurrentDirectory " ++ "\"" ++ args ++ "\"")) 

Call the last one which is on :sbh Desktop/Sandbox/Haskell then.

+1
source

Source: https://habr.com/ru/post/1200666/


All Articles