问题描述
有没有办法从monad中取出东西?
我正在开发一款游戏,现在我正在尝试了解数据库。我发现 happstack
例如,我有这个功能(希望您熟悉 happstack
)
getAllThings :: MonadIO m => m [事物]
getAllThings =做
elems< - 查询GetThings
返回元素
所以我得到 m [物品]
,但我不能在我的模型中使用它!例如
doSomeThingWithThings :: [Thing] - >
我搜索了这个,我什么也没找到。
您不应该以这种方式退出IO monad(除 unsafePerformIO
函数),但仍然可以在内部使用您的函数它:
process :: MonadIO m => m()
process = do
elems< - getAllThings
let smth = doSomeThingWithThings elems
- ...
Is there any way to take "things" out of a monad?
I am developing a game, and I am now trying to understand about databases. I found happstack
really nice, but I can't get the thing.
For example, I have this function (hope you are familiar with happstack
)
getAllThings :: MonadIO m => m [Thing]
getAllThings = do
elems <- query GetThings
return elems
So I get m [Things]
, but I can't use this in my model! For instance
doSomeThingWithThings :: [Thing] -> Something
I googled this and I found nothing.
You are not supposed to exit IO monad this way (except unsafePerformIO
function), but you can still use your function inside it:
process :: MonadIO m => m ()
process = do
elems <- getAllThings
let smth = doSomeThingWithThings elems
-- ...
这篇关于如何从Haskell中的monad中取出一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!