OverloadedStrings不太合适

 拍友2602909025 发布于 2023-02-08 07:03

此代码给出以下错误.我该如何解决?

230     let pipeline = [ ["$match" =: matchSelect],
231                         ["$group" =: ["_id" =: empty, "sum" =:
232                             ["$sum" =: "$score"]]] ]

Add.hs:232:40:
    No instance for (Data.String.IsString v0)
      arising from the literal `"$score"'
    The type variable `v0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    Note: there are several potential instances:
      instance Data.String.IsString Data.Text.Internal.Text
        -- Defined in `Data.Text'
      instance Data.String.IsString [Char] -- Defined in `Data.String'
    In the second argument of `(=:)', namely `"$score"'
    In the expression: "$sum" =: "$score"
    In the second argument of `(=:)', namely `["$sum" =: "$score"]'
Failed, modules loaded: Utils, Delete, Get, Migrate, Review, Validate.

GS - Apologi.. 8

(=:)具有多态类型,其中在结果类型中未提及参数中提到的类型变量,因此编译器没有足够的数量来决定表达式中第二个参数的类型"$sum" =: "$score".

字符串文字"$score"给出约束IsString v0,并(=:)给出约束Val v0,但实际上并没有说"它必须是这种类型",并且由于最终结果是Field没有提及的类型,v因此最终结果的使用方式无关紧要v.

最简单的方法是给出"$score"一个类型签名,例如("$score" :: String)你真正想要的其他类型.

1 个回答
  • (=:)具有多态类型,其中在结果类型中未提及参数中提到的类型变量,因此编译器没有足够的数量来决定表达式中第二个参数的类型"$sum" =: "$score".

    字符串文字"$score"给出约束IsString v0,并(=:)给出约束Val v0,但实际上并没有说"它必须是这种类型",并且由于最终结果是Field没有提及的类型,v因此最终结果的使用方式无关紧要v.

    最简单的方法是给出"$score"一个类型签名,例如("$score" :: String)你真正想要的其他类型.

    2023-02-08 07:16 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有