我有一个函数。假设它看起来像这样:
strangeFunc = do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code
然后,我希望它永远运行,所以我这样做
strangeFunc = forever $ do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code
但我有一个错误:变量不在范围内:永远
。我该如何修复它?
最佳答案
您必须从 Control.Monad
导入forever
。将其添加到文件顶部:
import Control.Monad (forever)
当编译器说变量不在范围内...
时,这意味着“我不知道这应该是什么;你还没有定义它。”这可能是由于没有导入所需的模块造成的。
我怎么知道这个?如果你search for forever
on Hoogle ,它表示它位于 base
包的 Control.Monad
模块中。因此,您必须导入它才能使用它。
关于haskell - 应该如何使用forever函数呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53451323/