aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/abstract/hash.lux
blob: 3a27317de7f38d9b10c1f461f1a797c2b4012e74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(.module:
  [library
   [lux #*]]
  [//
   ["." equivalence (#+ Equivalence)]
   [functor
    ["." contravariant]]])

(interface: .public (Hash a)
  {#.doc (example "A way to produce hash-codes for a type's instances."
                  "A necessity when working with some data-structures, such as dictionaries or sets.")}
  (: (Equivalence a)
     &equivalence)
  (: (-> a Nat)
     hash))

(implementation: .public functor
  (contravariant.Functor Hash)
  
  (def: (map f super)
    (implementation
     (def: &equivalence
       (\ equivalence.functor map f
          (\ super &equivalence)))
     
     (def: hash
       (|>> f (\ super hash))))))