No matching definitions.

tur/typeclass-hash

stdlib/typeclass-hash.tur

minimal Hash typeclass stub for typed-collection keys.

Auto-loaded so map and other content-keyed collections can resolve (Hash K) constraints for primitive key types without importing typeclass.tur. Mirrors typeclass-eq.tur: it declares the Hash class plus the four primitive instances most likely to appear as map keys. The full typeclass.tur no longer re-declares Hash, so loading it on demand stays idempotent against this stub.

Since: Phase GHE0

defclass

Hash

(defclass Hash [a])

values that hash to an integer, for content-keyed maps and sets.

athe type to hash
(hash [x] :int)

an :int hash of x, suitable as a HAMT key.

(eq? x y) implies (= (hash x) (hash y))
(hash 42)   ; => 42
(hash true) ; => 1

The converse is not required: unequal values may collide.

Since: Phase TM0

definstance

Hash[int]

(definstance Hash [int])

Hash instance for int (identity hash).

definstance

Hash[bool]

(definstance Hash [bool])

Hash instance for bool (0 for false, 1 for true).

definstance

Hash[cstr]

(definstance Hash [cstr])

Hash instance for cstr (content hash via tur_hamt_hash_str).

definstance

Hash[float32]

(definstance Hash [float32])

Hash instance for float32 (bit-cast and hash).

definstance

Hash[float]

(definstance Hash [float])

Hash instance for float (float64): hash the IEEE-754 bits.

Without this instance a :float (64-bit) map key falls back to the int hash, which numerically truncates 1.5 -> 1 and collapses distinct keys. Bit-casting the double to its int64 pattern hashes by value instead.

definstance

Hash[Sym]

(definstance Hash [Sym])

hash a dynamically-typed value by its runtime type.

set-of-element-type-is-not-checked / saffron-lang-plan S6: the honest type of a heterogeneous set is (Set any), and a (Set any) needs Hash[any]. Each is? arm narrows x to the payload type, so the hash is exactly the one that payload would have had unboxed -- an any holding 1 hashes as (hash 1), which is what lets a plain 1 probe a (Set any) and find it. Any other payload hashes by its TYPE NAME: correct (equal values agree) but coarse (every value of that type collides), which is the v0 trade for not reading an arbitrary payload word. The Sym arm is what keeps keyword keys apart: without it #set{:a :b :c} hashed every keyword by the name "Sym" and kept ONE element (saffron-dynamic-surface-pass H4). Pure Turmeric, so both back ends agree without a native. The arms use the .hash method spelling on purpose: a bare hash resolves in the VALUE namespace, where a user (defn hash ...) legitimately shadows the method (TUR-W0039), and this body is elaborated in the user's program.

saffron-dynamic-surface-pass H4: the Sym instance lives HERE, beside its class, rather than in sym.tur (which the autoloader reads later), so that the any instance below can name it in its Sym arm. Non-orphan either way: the class is defined in this module. Hash [Sym] -- hash a symbol via its precomputed hash field (a single load).

Since: saffron-lang-plan S6 (Hash[any])

definstance

Hash[any]

(definstance Hash [any])