Haskell数据构造函数不在范围中
我一直在研究它,并想与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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须导入导出这些功能的模块;在这种情况下,
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.