gpt4 book ai didi

haskell - 如何在 GHCi 中设置当前目录?

转载 作者:行者123 更新时间:2023-12-03 15:27:14 24 4
gpt4 key购买 nike

我是 Haskell 的新手,使用的是 Windows PC。我正在尝试设置我的 GHCi 界面,以便我可以在使用 GHCi 执行之前在我的文本编辑器中编写我的代码。

目前,我的 GHCi 读取

$ ghci GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help 
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude>

据此 site ,我必须将我的 Haskell 文件保存到当前目录或指定其他目录才能访问它们。这是我不知道该怎么做。

我的问题:
  • 如何设置当前目录?
  • 如何让 GHCi 告诉我当前目录的路径是什么,以便我可以在需要时检查它的设置?

  • 请从行开始解释
    Prelude>

    如上所述,以便我可以跟进。

    注:

    给出的示例 Haskell 代码是

    文件名:Main.hs
    main = print(fac(20))

    fac 0 = 1
    fac n = n * fac(n-1)

    在 GHCi 中
    prelude> :load Main 
    Compiling Main ( Main.hs, interpreted )
    Ok, modules loaded: Main.
    *Main> fac 17
    355687428096000

    所以我想把Main.hs保存到一个目录,指定这个为GHCi中的当前目录,然后运行上面的代码。

    最佳答案

    How do I set the current directory?



    GHCi 提供 :cd <dir>命令。您可以使用 :? 获取所有命令的列表.如果您省略目录,您将再次更改为您的主目录。

    How do I get the GHCi to tell me what the path for current directory is so I can check what it is set at when I want to?



    有趣的是,GHCi 没有为此提供命令,但您可以使用 Window 的 cd命令。为了执行外部命令,您需要使用 :! ,例如 :! cd .

    例子

    ghci> :!光盘
    C:\用户\Zeta
    ghci> :cd 工作区
    ghci> :cd 堆栈溢出
    ghci> :!光盘
    C:\Users\Zeta\workspace\stackoverflow
    ghci> :cd
    ghci> :!cd
    C:\用户\Zeta

    关于haskell - 如何在 GHCi 中设置当前目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31213315/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com