lean4-htt/src/Init/Data/Hashable.lean
Daniel Fabian ed75005422 feat: make proofs Hashable
change the `Hashable` class from taking a hash function of `Type u` to taking a
hash function from `Sort u`. This allows to implement `Hashable` for
propositions, which in turn is needed for inductives carrying proofs
2021-03-30 13:36:52 -07:00

49 lines
No EOL
1.1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.UInt
import Init.Data.String
universes u
instance : Hashable Nat where
hash n := USize.ofNat n
instance [Hashable α] [Hashable β] : Hashable (α × β) where
hash | (a, b) => mixHash (hash a) (hash b)
instance : Hashable Bool where
hash
| true => 11
| false => 13
protected def Option.hash [Hashable α] : Option α → USize
| none => 11
| some a => mixHash (hash a) 13
instance [Hashable α] : Hashable (Option α) where
hash
| none => 11
| some a => mixHash (hash a) 13
instance [Hashable α] : Hashable (List α) where
hash as := as.foldl (fun r a => mixHash r (hash a)) 7
instance : Hashable UInt32 where
hash n := n.toUSize
instance : Hashable UInt64 where
hash n := n.toUSize
instance : Hashable USize where
hash n := n
instance : Hashable Int where
hash
| Int.ofNat n => USize.ofNat (2 * n)
| Int.negSucc n => USize.ofNat (2 * n + 1)
instance (P : Prop) : Hashable P where
hash := Function.const P 0