使用 HashMap 求和类型

问题描述

以下代码触发错误:

B

编译器抱怨:

B

如何创建像 import Data.HashMap.Strict (HashMap) -- from unordered-containers import Data.Text data Value = VText Text | VList [Text] | VMap HashMap Text Text deriving Show 这样的和类型,其中一个构造函数采用 Expecting two more arguments to ‘HashMap’ Expected a type,but ‘HashMap’ has kind ‘* -> * -> *’ In the type ‘HashMap’ In the definition of data constructor ‘VMap’ In the data declaration for ‘Value’typecheck

解决方法

通过使用括号来消除 HashMapVMap 的参数歧义:

data Value =
    VText Text
  | VList [Text]
  | VMap (HashMap Text Text)
  deriving Show

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...