问题描述
是否可以在ghci.conf文件中设置别名?
Is it possible to set aliases in the ghci.conf file?
例如,我在bash.bashrc中具有 alias sbh ='cd Desktop/Sandbox/Haskell'
,可以让我快速跳转到指定的文件夹.通过在ghci.conf文件中添加别名,是否可以在ghci中实现同样的目的?
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?
我在ghci.conf中已经有一些命令,但是我想设置多个别名以跳转到文件夹位置,而不必使用:cd home/sandbox/foo/bar
时间.我在Google上找不到任何东西,所以它以前从未被考虑过,或者只是缺少了一些非常简单的东西.
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.
推荐答案
:def
命令可以执行以下操作:
The :def
command can do this:
:def sbh const $ return ":cd Desktop/Sandbox/Haskell"
如您所见,它比仅提供替换字符串要复杂一些:它使用类型为 String->的Haskell函数.新定义的命令将IO String
应用于其自变量字符串,以计算要运行的新命令.
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.
然后在GHCI :sbh
中调用.
Then in GHCI :sbh
to invoke.
这篇关于Haskell/GHCI中的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!