test: add test to demonstrate why it is useful to include instances in the PersistentHashMap type
This commit is contained in:
parent
d9fb5acb22
commit
6d358a5dee
2 changed files with 19 additions and 0 deletions
11
tests/lean/phashmap_inst_coherence.lean
Normal file
11
tests/lean/phashmap_inst_coherence.lean
Normal 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
|
||||
8
tests/lean/phashmap_inst_coherence.lean.expected.out
Normal file
8
tests/lean/phashmap_inst_coherence.lean.expected.out
Normal 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)
|
||||
Loading…
Add table
Reference in a new issue