test: add test to demonstrate why it is useful to include instances in the PersistentHashMap type

This commit is contained in:
Leonardo de Moura 2019-11-08 08:23:10 -08:00
parent d9fb5acb22
commit 6d358a5dee
2 changed files with 19 additions and 0 deletions

View file

@ -0,0 +1,11 @@
import Init.Data.PersistentHashMap
def m : PersistentHashMap Nat Nat :=
let m : PersistentHashMap Nat Nat := {};
m.insert 1 1
def natDiffHash : Hashable Nat :=
⟨fun n => USize.ofNat $ n+10⟩
-- The following example should fail since the `Hashable` instance used to create `m` is not `natDiffHash`
#eval @PersistentHashMap.find Nat Nat _ natDiffHash m 1

View file

@ -0,0 +1,8 @@
phashmap_inst_coherence.lean:11:0: error: type mismatch at application
PersistentHashMap.find m
term
m
has type
@PersistentHashMap Nat Nat Nat.Hashable (@beqOfEq Nat Nat.DecidableEq)
but is expected to have type
@PersistentHashMap Nat Nat natDiffHash (@beqOfEq Nat Nat.DecidableEq)