我是 Haskell 和 Yesod 的新手,我正在尝试使用 Control.Concurrent.Async
模块来执行异步操作。 (代码基于:https://hackage.haskell.org/package/async-2.1.1/docs/Control-Concurrent-Async.html#v:withAsync)
quizWidget = do
--Get first question
withAsync (showQuizItem 1 1 ) $ \qi -> do
withAsync (showScoreboard) $ \sb -> do
quizItem <- wait (qi)
scoreboard <- wait (sb)
toWidget $(hamletFile "hamlet/quiz.hamlet")
但这会产生以下错误:
"No instance for (MonadWidget IO) arising from a use of ‘toWidget’".
所以问题是我做错了什么?
最佳答案
异步包中的 API 是单态的,这意味着它仅适用于 IO
中的操作。您尝试在 WidgetT
转换器类型中使用它,这就是错误消息的来源。您可以使用 lifted-async包,它提供了 withAsync 函数的多态变体。在大多数情况下,这应该只是一个问题:
- 导入
Control.Concurrent.Async.Lifted
- 将
lifted-async
添加到您的build-depends
关于haskell - 是的,withAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42503446/