aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/type.lux
blob: f7d1e3f64f146d53d7a6db7d06166263df67515e (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
(.using
 [library
  [lux {"-" function as let}
   ["$" documentation {"+" documentation:}]
   [control
    ["<>" parser
     ["<[0]>" code]]]
   [data
    ["[0]" text {"+" \n}
     ["%" format]]]
   [macro
    ["[0]" template]]]]
 [\\library
  ["[0]" /]]
 ["[0]" / "_"
  ["[1][0]" primitive]
  ["[1][0]" check]
  ["[1][0]" dynamic]
  ["[1][0]" implicit]
  ["[1][0]" poly]
  ["[1][0]" quotient]
  ["[1][0]" refinement]
  ["[1][0]" resource]
  ["[1][0]" unit]
  ["[1][0]" variance]])

(template [<name>]
  [(documentation: <name>
     "The number of parameters, and the body, of a quantified type.")]

  [/.flat_univ_q]
  [/.flat_ex_q]
  )

(documentation: /.flat_function
  "The input, and the output of a function type."
  [(flat_function type)])

(documentation: /.flat_application
  "The quantified type, and its parameters, for a type-application."
  [(flat_application type)])

(template [<name>]
  [(documentation: <name>
     "The members of a composite type.")]

  [/.flat_variant]
  [/.flat_tuple]
  )

(documentation: /.format
  "A (readable) textual representable of a type."
  [(format type)])

(documentation: /.applied
  "To the extend possible, applies a quantified type to the given parameters."
  [(applied params func)])

(documentation: /.code
  (%.format "A representation of a type as code."
            \n "The code is such that evaluating it would yield the type value.")
  [(code type)])

(documentation: /.de_aliased
  "A (potentially named) type that does not have its name shadowed by other names."
  [(de_aliased type)])

(documentation: /.anonymous
  "A type without any names covering it."
  [(anonymous type)])

(template [<name>]
  [(documentation: <name>
     "A composite type, constituted by the given member types.")]

  [/.variant]
  [/.tuple]
  )

(documentation: /.function
  "A function type, with the given inputs and output."
  [(function inputs output)])

(documentation: /.application
  "An un-evaluated type application, with the given quantified type, and parameters."
  [(application params quant)])

(template [<name>]
  [(documentation: <name>
     "A quantified type, with the given number of parameters, and body.")]

  [/.univ_q]
  [/.ex_q]
  )

(documentation: /.quantified?
  "Only yields #1 for universally or existentially quantified types."
  [(quantified? type)])

(documentation: /.array
  "An array type, with the given level of nesting/depth, and the given element type."
  [(array depth element_type)])

(documentation: /.flat_array
  "The level of nesting/depth and element type for an array type."
  [(flat_array type)])

(documentation: /.array?
  "Is a type an array type?")

(documentation: /.log!
  "Logs to the console/terminal the type of an expression."
  [(log! (is Foo (foo expression)))
   "=>"
   "Expression: (foo expression)"
   "      Type: Foo"
   (foo expression)])

(documentation: /.as
  (%.format "Casts a value to a specific type."
            \n "The specified type can depend on type variables of the original type of the value."
            \n "NOTE: Careless use of type-casts is an easy way to introduce bugs. USE WITH CAUTION.")
  [(is (Bar Bit Nat Text)
       (as [a b c]
           (Foo a [b c])
           (Bar a b c)
           (is (Foo Bit [Nat Text])
               (foo expression))))])

(documentation: /.sharing
  "Allows specifing the type of an expression as sharing type-variables with the type of another expression."
  [(is (Bar Bit Nat Text)
       (sharing [a b c]
                (Foo a [b c])
                (is (Foo Bit [Nat Text])
                    (foo expression))
                
                (Bar a b c)
                (bar expression)))])

(documentation: /.by_example
  "Constructs a type that shares type-variables with an expression of some other type."
  [(is Type
       (by_example [a b c]
                   (Foo a [b c])
                   (is (Foo Bit [Nat Text])
                       (foo expression))
                   
                   (Bar a b c)))
   "=>"
   (.type (Bar Bit Nat Text))])

(documentation: /.let
  "Local bindings for types."
  [(let [side (Either Int Frac)]
     (List [side side]))])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            "Basic functionality for working with types."
            [..flat_univ_q
             ..flat_ex_q
             ..flat_function
             ..flat_application
             ..flat_variant
             ..flat_tuple
             ..format
             ..applied
             ..code
             ..de_aliased
             ..anonymous
             ..variant
             ..tuple
             ..function
             ..application
             ..univ_q
             ..ex_q
             ..quantified?
             ..array
             ..flat_array
             ..array?
             ..log!
             ..as
             ..sharing
             ..by_example
             ..let
             ($.default /.equivalence)]
            [/primitive.documentation
             /check.documentation
             /dynamic.documentation
             /implicit.documentation
             /poly.documentation
             /quotient.documentation
             /refinement.documentation
             /resource.documentation
             /unit.documentation
             /variance.documentation]))