haskell - haskell 模拟:在具有类约束的数据类型中定义 func
问题描述
有功能
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)
我什至不知道它们之间的确切区别
推荐阅读
- javascript - 如何在 laravel 8 中使用来自 npm 的 twitter 引导程序
- elasticsearch - 序列化响应时,BucketAggregate 上的“键”丢失
- bootstrap-4 - 带有引导程序的 Tampermonkey 脚本不起作用
- c++ - f(T&()) 的模板参数推导是如何发生的?
- android - 从协程范围返回值而不使用 runBlocking
- java - 从特定帖子的 Firebase 获取密钥
- c# - ASP.NET Core - 为 WebAPI 使用 Cookie 和 JWT
- c++ - 输出未正确递增 - C++
- video - 使用 `ffmpeg` 将专辑封面艺术添加到 FLAC 音频文件
- godot - 等轴测视图中的 8 方向基于网格的运动