aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/type/implicit.lux
blob: 3152aa23da70fbf03358859a5ec8e7135945d040 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(.require
 [library
  [lux (.except and)
   ["$" documentation (.only documentation:)]
   [control
    ["<>" parser
     ["<[0]>" code]]]
   [data
    ["[0]" text (.only \n)
     ["%" \\format (.only format)]]]
   [macro
    ["[0]" template]]]]
 [\\library
  ["[0]" /]])

(documentation: /.a/an
  (format "Automatic implementation selection (for type-class style polymorphism)."
          \n "This feature layers type-class style polymorphism on top of Lux's signatures and implementations."
          \n "When calling a polymorphic function, or using a polymorphic constant,"
          \n "this macro will check the types of the arguments, and the expected type for the whole expression"
          \n "and it will search in the local scope, the module's scope and the imports' scope"
          \n "in order to find suitable implementations to satisfy those requirements."
          \n "If a single alternative is found, that one will be used automatically."
          \n "If no alternative is found, or if more than one alternative is found (ambiguity)"
          \n "a compile-time error will be raised, to alert the user."
          \n \n "Caveat emptor: You need to make sure to import the module of any implementation you want to use."
          \n "Otherwise, this macro will not find it.")
  ["Nat equivalence"
   (at number.equivalence = x y)
   (a/an = x y)]
  ["Can optionally add the prefix of the module where the signature was defined."
   (a/an equivalence.= x y)]
  ["(List Nat) equivalence"
   (a/an =
         (list.indices 10)
         (list.indices 10))]
  ["(Functor List) each"
   (a/an each ++ (list.indices 10))])

(documentation: /.with
  "Establish lexical bindings for implementations that will be prioritized over non-lexically-bound implementations."
  [(with [n.addition]
     (n.= (at n.addition composite left right)
          (a/an composite left right)))])

(documentation: /.implicitly
  "Establish local definitions for implementations that will be prioritized over foreign definitions."
  [(implicitly n.multiplication)
   
   (n.= (at n.multiplication composite left right)
        (a/an composite left right))])

(.def .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..a/an
             ..with
             ..implicitly]
            []))