永久功能应如何使用? [英] How should the forever function be used?
问题描述
我有一个功能.假设它看起来像这样:
I have a function. Let's say it looks like this:
strangeFunc = do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code
然后,我希望它永远运行,所以我这样做
Then, I want it to run forever, so I do this
strangeFunc = forever $ do
putStrLn "Welcome to the game! Please, enter the name of the file: "
--some more code
但是我有一个错误:variable not in scope: forever
.我该如何解决?
But I have an error: variable not in scope: forever
. How can I fix it?
推荐答案
您必须从Control.Monad
导入forever
.将此添加到文件顶部:
You must import forever
from Control.Monad
. Add this to the top of your file:
import Control.Monad (forever)
当编译器说variable not in scope...
时,表示我不知道这应该是什么;您尚未定义它".这可能是由于未导入所需的模块引起的.
When the compiler says variable not in scope...
, it means "I don't know what this is supposed to be; you haven't defined it." This can be caused by not having the required modules imported.
我怎么知道的?如果您在Hoogle中搜索forever
,则表示它位于Control.Monad
模块,位于base
包中.因此,您必须导入它才能使用它.
How did I know this? If you search for forever
on Hoogle, it says that it is in the Control.Monad
module, in the base
package. Hence, you must import it in order to use it.
这篇关于永久功能应如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!