简体   繁体   English

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

[英]Running `cabal repl` with Top-level Functions

I'm trying to learn to sandbox my Haskell projects with cabal. 我正在尝试用cabal学习沙盒我的Haskell项目。

I make extensive use of the command interpreter ghci , which imports top-level functions by default. 我广泛使用命令解释器ghci ,它默认导入顶级函数。

cabal repl also provides a command interpreter, but top-level functions are not imported. cabal repl还提供了一个命令解释器,但不导入顶级函数。

How can I run cabal repl so that top-level constants and functions will be defined in the command interpreter? 如何运行cabal repl以便在命令解释器中定义顶级常量和函数?

Here's a minimal example: 这是一个最小的例子:

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

main :: IO ()
main = undefined

Now, someConstant will be defined when I run ghci somefile.hs , but it won't be defined when I run cabal repl . 现在,当我运行ghci somefile.hs时会定义someConstant ,但是当我运行cabal repl时它不会被定义。

If the module is one listed in your project (ie in your exposed-modules or other-modules sections): 如果模块是项目中列出的模块(即在您的公开模块或其他模块部分中):

:m *ModuleName

Otherwise: 除此以外:

:l somefile.hs

See also What's really in scope at the prompt? 另请参见提示符范围内的真实内容? from the Fine Documentation. 来自精细文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM