Reason 如何在ReScript中为任意记录类型实现哈希函数?

Reason 如何在ReScript中为任意记录类型实现哈希函数?,reason,bucklescript,rescript,Reason,Bucklescript,Rescript,这是我第一次探索《重新书写》。我想使用记录类型作为键类型构建一个hashmap,我正在寻找关于实现hash函数的指导 这是我的命令代码: type pointer = { id: string, table: string, spaceId: option<string> } module PointerHash = Belt.Id.MakeHashable({ type t = pointer let hash = a => 0 /* How do I implem

这是我第一次探索《重新书写》。我想使用记录类型作为键类型构建一个hashmap,我正在寻找关于实现hash函数的指导

这是我的命令代码:

type pointer = { id: string, table: string, spaceId: option<string> }

module PointerHash = Belt.Id.MakeHashable({
  type t = pointer
  let hash = a => 0 /* How do I implement this? */
  let eq = (a, b) => 
    a.id == b.id &&
    a.table == b.table &&
    switch (a.spaceId, b.spaceId) {
      | (Some(aid), Some(bid)) => aid == bid
      | _ => false
    }
})

我查看了,看看是否有任何提示,它看起来像HashMapString使用了
caml\u hash\u mix\u string

external caml\u hash\u mix\u string:seed->string->seed=“caml\u hash\u mix\u string”
外部最终混合:seed->seed=“caml\u hash\u final\u mix”
让散列(s:key)=
最终混合(caml\u散列\u混合\u字符串0 s)

访问和编写“hash mix”函数最惯用的方法是什么?ReScript的界面好吗?

Hashtbl
模块中有一个内置的多态哈希函数:

let hash: 'a => int

这来自ReScript继承的OCaml标准库。您可以在那里找到文档:

皮带中是否有等效物?@AllainLonde否,但由于在ReScript中提供了开箱即用的
Hashtbl.hash
,因此您不需要皮带中的等效物。