使用 `cabal repl` 运行顶层函数

3

我正在尝试使用cabal来隔离我的Haskell项目。

我经常使用命令解释器ghci,默认情况下会导入顶层函数。

cabal repl也提供了一个命令解释器,但是不会导入顶层函数。

我该如何运行cabal repl以便在命令解释器中定义顶层常量和函数?

这里是一个最简示例:

-- somefile.hs
someConstant :: Int
someConstant = 5

main :: IO ()
main = undefined

现在,当我运行ghci somefile.hs时,someConstant会被定义,但是当我运行cabal repl时,它不会被定义。
1个回答

4
如果该模块在您的项目中列出(即在您的 exposed-modules 或 other-modules 部分):
:m *ModuleName

否则:

:l somefile.hs

请参阅Fine文档中提示符中真正的范围是什么?

1
我认为文件名也应该以大写字母开头,就像这里提到的一样。 - Sibi
"What’s really in scope at the prompt?" 的新链接:https://downloads.haskell.org/ghc/latest/docs/users_guide/ghci.html#ghci-scope - Cigarette Smoking Man

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接