下面是从对象解析Int的代码。但无法找到Key的正确导入。
parseInt :: Object -> Key -> Parser Int
parseInt v field =
asum
[ v .: field,
do
s <- v .: field
case readMaybe s :: Maybe Int of
Nothing -> fail "not a number"
Just x -> return x
]我试过了
import Data.Aeson和
import Data.Aeson.Types但是得到错误
Not in scope: type constructor or class ‘Key’
A data constructor of that name is in scope; did you mean DataKinds?在我的函数中,Key的正确导入应该是什么?
发布于 2022-01-19 05:54:14
看起来您正在编写针对aeson 2.x的代码,但是已经安装了aeson 1.x。要么升级(推荐),要么使用Text代替Key。
https://stackoverflow.com/questions/70765818
复制相似问题