lean4-htt/src/Init/Data/Hashable.lean
Leonardo de Moura cca3bad0bb feat: add Prelude.lean
`Prelude.lean` has no dependencies, and
at the end of `Prelude`, the `syntax` and `macro` commands are operational.
2020-11-10 18:08:18 -08:00

31 lines
787 B
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 := {
hash := fun n => USize.ofNat n
}
instance {α β} [Hashable α] [Hashable β] : Hashable (α × β) := {
hash := fun (a, b) => mixHash (hash a) (hash b)
}
protected def Option.hash {α} [Hashable α] : Option α → USize
| none => 11
| some a => mixHash (hash a) 13
instance {α} [Hashable α] : Hashable (Option α) := {
hash := fun
| none => 11
| some a => mixHash (hash a) 13
}
instance {α} [Hashable α] : Hashable (List α) := {
hash := fun as => as.foldl (fun r a => mixHash r (hash a)) 7
}