gpt4 book ai didi

http - 在 Haskell 中学习 Conduits 时与 MonadBaseControl 错误混淆

转载 作者:可可西里 更新时间:2023-11-01 16:21:50 26 4
gpt4 key购买 nike

我正在尝试学习 Haskell 中的 Conduits。这听起来很有趣,但类型很快就会变得非常困惑。

到目前为止,我已经编写了以下文件:https://gist.github.com/anonymous/7991727

据推测,它会做的是,给定一系列股票代码,它会转到雅虎财经并下载相关的数据文件。听起来很简单。

getLinkextractLink 效果很好。那里没有问题。

downloadContent 给我各种编译问题。此源代码:

downloadContent manager = do
mx <- await
case mx of
Nothing -> return ()
Just (sym, Nothing) -> return ()
Just (sym, Just link) -> do
req <- parseUrl link
res <- http req manager
responseBody res $$+- sinkFile sym

我得到的确切错误是:

src/suckyahoo.hs:58:21:
No instance for (MonadBaseControl
IO
(ConduitM
[Char] ([Char], Maybe String) (ResourceT (ResourceT IO))))
arising from a use of `getLink'
Possible fix:
add an instance declaration for
(MonadBaseControl
IO
(ConduitM
[Char] ([Char], Maybe String) (ResourceT (ResourceT IO))))
In the second argument of `($=)', namely `getLink manager'
In the first argument of `($$)', namely
`sourceSyms $= getLink manager'
In a stmt of a 'do' block:
sourceSyms $= getLink manager $$ downloadContent manager

src/suckyahoo.hs:58:40:
No instance for (MonadBaseControl
IO
(ConduitM
(FilePath, Maybe String)
void-0.6.1:Data.Void.Void
(ResourceT (ResourceT IO))))
arising from a use of `downloadContent'
Possible fix:
add an instance declaration for
(MonadBaseControl
IO
(ConduitM
(FilePath, Maybe String)
void-0.6.1:Data.Void.Void
(ResourceT (ResourceT IO))))
In the second argument of `($$)', namely `downloadContent manager'
In a stmt of a 'do' block:
sourceSyms $= getLink manager $$ downloadContent manager
In the expression:
do { sourceSyms $= getLink manager $$ downloadContent manager }
Failed, modules loaded: none.

这里有什么洞察力可以让我实现代码的意图?

最佳答案

您必须将您的操作提升到管道的底层 monad:

downloadContent manager = do
mx <- await
case mx of
Nothing -> return ()
Just (sym, Nothing) -> return ()
Just (sym, Just link) -> lift $ do
req <- parseUrl link
res <- http req manager
responseBody res $$+- sinkFile sym

关于http - 在 Haskell 中学习 Conduits 时与 MonadBaseControl 错误混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20618076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com