How does one implement hash tables in a functional language?

后端 未结 3 1730
清歌不尽
清歌不尽 2020-12-28 14:37

Is there any way to implement hash tables efficiently in a purely functional language? It seems like any change to the hash table would require creating a copy of the origi

3条回答
  •  我在风中等你
    2020-12-28 15:26

    Hash tables can be implemented with something like the ST monad in Haskell, which basically wraps IO actions in a purely functional interface. It does so by forcing the IO actions to be performed sequentially, so it maintains referential transparency: you can't access the old "version" of the hash-table.

    See: hackage.haskell.org/package/hashtables

提交回复
热议问题