gpt4 book ai didi

haskell 模拟 : define func in datatype with class-constraint

转载 作者:行者123 更新时间:2023-12-05 07:28:23 24 4
gpt4 key购买 nike

有这个功能

httpLBS :: MonadIO m => Request -> m (Response ByteString) 

Network.HTTP.Simple 模块 ( doc ) 中,我想将其与我的 Ctx 数据一起传递(以便稍后在集成测试中进行模拟) -对象

data Ctx =
Ctx {
token :: String,
httpLBSFunc :: MonadIO m => Request -> m (Response ByteString)
} deriving (Show)

但是我收到了这个错误:

Prelude> :l Context.hs
[1 of 1] Compiling Context ( Context.hs, interpreted )

Context.hs:19:32: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^

Context.hs:19:48: error: Not in scope: type variable ‘m’
|
19 | httpLBSFunc :: MonadIO m => Request -> m (Response B.ByteString)
| ^
Failed, no modules loaded.

如何在我的 Ctx 数据类型中正确定义此方法??

最佳答案

我不知道用实际的 Monad IO 替换约束 MonadIO 有什么缺点,但对我来说这足以让它运行:

data Ctx =
Ctx {
token :: String,
httpLBSFunc :: Request -> IO (Response ByteString)
} deriving (Show)

我什至不知道它们之间的确切区别

关于haskell 模拟 : define func in datatype with class-constraint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53375057/

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