永久功能应如何使用?

编程入门 行业动态 更新时间:2024-10-26 03:22:08
本文介绍了永久功能应如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个功能.假设它看起来像这样:

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.

更多推荐

永久功能应如何使用?

本文发布于:2023-11-23 09:03:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620865.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应如何   功能

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!