无法将预期类型 'Control.Monad.Trans.Reader.ReaderT MongoContext IO a0' 与实际类型 'IO ()' 匹配
Couldn't match expected type 'Control.Monad.Trans.Reader.ReaderT MongoContext IO a0' with actual type 'IO ()'
我想打印取自 mongoDB 的点图,然后转换成图像。
run = do
docs <- timeFilter -- function to fetch [Document] from mongoDB
let dot = onlyDot docs -- exclude extra field from the documents
let dotObject = getObjId dot -- convert into an object
-- converting dot graph to string and then string to text to pass it on to parseDotGraph function
let xDotGraph = parseDotGraph (B.pack (show dotObject)) :: G.DotGraph String
Prelude.putStrLn $ B.unpack $ renderDot $ toDot xDotGraph -- this is not working, want to print
-- addExtension (runGraphviz xDotGraph) Png "graph" -- this is not working, want to draw as an image
printDocs dot
您需要 liftIO $
在 Prelude.putStrLn
的左侧,但下次粘贴带有行号等的完整错误。您的 do 块位于 ReaderT MongoContext IO
monad 中,其中包含 IO
因此您可以在其中执行 IO
操作,但您必须先解除它们。
我想打印取自 mongoDB 的点图,然后转换成图像。
run = do
docs <- timeFilter -- function to fetch [Document] from mongoDB
let dot = onlyDot docs -- exclude extra field from the documents
let dotObject = getObjId dot -- convert into an object
-- converting dot graph to string and then string to text to pass it on to parseDotGraph function
let xDotGraph = parseDotGraph (B.pack (show dotObject)) :: G.DotGraph String
Prelude.putStrLn $ B.unpack $ renderDot $ toDot xDotGraph -- this is not working, want to print
-- addExtension (runGraphviz xDotGraph) Png "graph" -- this is not working, want to draw as an image
printDocs dot
您需要 liftIO $
在 Prelude.putStrLn
的左侧,但下次粘贴带有行号等的完整错误。您的 do 块位于 ReaderT MongoContext IO
monad 中,其中包含 IO
因此您可以在其中执行 IO
操作,但您必须先解除它们。