小编dl9*_*l96的帖子

查看String Map中是否存在键

我目前正在使用Map仿函数来创建字符串映射:module StringMap = Map.Make(String).

然后我尝试将一组字符串映射插入'aStringMap 中的对象列表.检查密钥是否已存在,我正在执行以下操作:

match StringMap.find_opt key my_map with
  | None -> StringMap.add key [child] my_map
  | Some l -> StringMap.add key (child::l) my_map 
Run Code Online (Sandbox Code Playgroud)

但是,当我编译时,我收到一个错误,说绑定find_opt有一个未绑定的值,即使它在签名中定义:https://ocaml.org/learn/tutorials/map.html.

我也试过使用StringMap.mem key my_map,但得到以下错误:

Error: This expression has type string but an expression was expected of type
     'a StringMap.t =
       (StringMap.Key.t, 'a, StringMap.Key.comparator_witness)
       Base__Map.t
Run Code Online (Sandbox Code Playgroud)

我环顾四周,看看是否有输入错误或其他东西,但一直无法找到任何东西.关于我为什么会遇到这些错误的任何想法?

ocaml dictionary

3
推荐指数
1
解决办法
411
查看次数

标签 统计

dictionary ×1

ocaml ×1