Haskell数据构造函数不在范围中

发布于 2025-02-01 18:05:39 字数 576 浏览 1 评论 0原文

我一直在研究它,并想与MVAR尝试一些代码。我正在通过在线编译器检查此代码。

以下是我要测试的代码:

main = do
  m <- newEmptyMVar
  forkIO $ putMVar m 'X'
  r <- takeMVar m
  print r

下面是我遇到的错误:

main.hs:2:8: error: Variable not in scope: newEmptyMVar :: IO t1

main.hs:3:3: error:
    Data constructor not in scope: IO :: t0 -> IO a0

main.hs:3:8: error:
    • Variable not in scope: putMVar :: t1 -> Char -> t0
    • Perhaps you meant ‘putChar’ (imported from Prelude)

main.hs:4:8: error: Variable not in scope: takeMVar :: t1 -> IO a1

I've been researching it and wanted to try out some code with MVar. I'm checking this code through an online compiler.

Below is the code I'm trying to test:

main = do
  m <- newEmptyMVar
  forkIO $ putMVar m 'X'
  r <- takeMVar m
  print r

And below here are the errors I'm getting:

main.hs:2:8: error: Variable not in scope: newEmptyMVar :: IO t1

main.hs:3:3: error:
    Data constructor not in scope: IO :: t0 -> IO a0

main.hs:3:8: error:
    • Variable not in scope: putMVar :: t1 -> Char -> t0
    • Perhaps you meant ‘putChar’ (imported from Prelude)

main.hs:4:8: error: Variable not in scope: takeMVar :: t1 -> IO a1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨扶苏 2025-02-08 18:05:39

您必须导入导出这些功能的模块;在这种情况下,control.concurrent将是一个不错的选择。如果您尚不知道需要哪个模块,一种发现的方法是使用 hoogle 。

You must import a module that exports these functions; in this case, Control.Concurrent would be a good choice. If you didn't already know which module was needed, one way to find out is to use Hoogle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文