Parsetree.expression 上的永久 Hashtbl.hash 碰撞

Permanent Hashtbl.hash collision on Parsetree.expression

无论我在 Exp.ident 参数中输入什么,结果 总是 产生相同的散列值。这是为什么?

utop # Hashtbl.hash (Exp.ident {Location.txt=(Longident.Lident "bar");loc=Location.none}) ;;
- : int = 99094472 

utop # Hashtbl.hash (Exp.ident {Location.txt=(Longident.Lident "foo");loc=Location.none}) ;;
- : int = 99094472

utop # Hashtbl.hash (Exp.ident {Location.txt=(Longident.Lident "");loc=Location.none}) ;;
- : int = 99094472  

是否Parsetree.expression使用了结构哈希生成器无法遍历的某种魔法数据结构?

为了保证hash总是终止,它有一个最大深度。 当列表的开头相同时,也会出现同样的问题。

如果这对你来说是必要的,一个好的解决方案是创建你自己的散列函数,在 Parsetree 的情况下,我建议你看一下 Ast_iterator.