Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Monad在mongodb访问中的应用_Mongodb_Haskell_Monads - Fatal编程技术网

Monad在mongodb访问中的应用

Monad在mongodb访问中的应用,mongodb,haskell,monads,Mongodb,Haskell,Monads,在下面的代码中,我对一些DB访问函数部分应用了DB连接(称为sharedPipe)。当数据库访问的最后一行是liftIO$PutStrLn“something”时,我可以使用IO()的返回类型。但是如果我想从函数返回结果,我必须返回一个类型Action IO()。当我运行代码时,编译器告诉我DB连接的预期类型是IO管道,而它的实际类型是Action IO管道,因为我访问了连接我已经将您的代码块减少到了有问题的组件。以下内容通过使用liftIO解决了您的问题: import Database.Mo

在下面的代码中,我对一些DB访问函数部分应用了DB连接(称为
sharedPipe
)。当数据库访问的最后一行是
liftIO$PutStrLn“something”
时,我可以使用
IO()
的返回类型。但是如果我想从函数返回结果,我必须返回一个类型
Action IO()
。当我运行代码时,编译器告诉我DB连接的预期类型是
IO管道
,而它的实际类型是
Action IO管道
,因为我访问了
连接我已经将您的代码块减少到了有问题的组件。以下内容通过使用
liftIO
解决了您的问题:

import Database.MongoDB
import Control.Monad.IO.Class

sharedPipe :: IO Pipe
sharedPipe = runIOE $ connect (host "127.0.0.1")

get :: [String] -> Action IO [String]
get = get' sharedPipe

get' :: IO Pipe -> [String] -> Action IO [String]
get' sharedPipe args = do
    pipe <- liftIO $ sharedPipe
    return []
import Database.MongoDB
导入控制.Monad.IO.Class
共享管道::IO管道
sharedPipe=runIOE$connect(主机“127.0.0.1”)
获取::[String]->操作IO[String]
获取=获取共享管道
获取“::IO管道->[String]->操作IO[String]
get'sharedPipe args=do

管道它看起来像
pipe这确实有帮助,但根本问题是我需要调用
access
,对返回
操作的函数执行操作。
import Database.MongoDB
import Control.Monad.IO.Class

sharedPipe :: IO Pipe
sharedPipe = runIOE $ connect (host "127.0.0.1")

get :: [String] -> Action IO [String]
get = get' sharedPipe

get' :: IO Pipe -> [String] -> Action IO [String]
get' sharedPipe args = do
    pipe <- liftIO $ sharedPipe
    return []