aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/meta/type.lux
blob: f2335eb248efb6f1a7a87ba199bcf9307931390e (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
(.require
 [library
  [lux (.except)
   ["$" documentation]
   [data
    ["[0]" text (.only \n)
     ["%" \\format (.only format)]]]
   [meta
    [macro
     ["[0]" template]]]]]
 ["[0]" \\parser]
 [\\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]])

(`` (.def \\parser
      (.List $.Module)
      ($.module \\parser._
                (format "Parsing of Lux types."
                        \n "Used mostly for polytypic programming.")
                [($.default \\parser.not_existential)
                 ($.default \\parser.not_recursive)
                 ($.default \\parser.not_named)
                 ($.default \\parser.not_parameter)
                 ($.default \\parser.unknown_parameter)
                 ($.default \\parser.not_function)
                 ($.default \\parser.not_application)
                 ($.default \\parser.not_polymorphic)
                 ($.default \\parser.not_variant)
                 ($.default \\parser.not_tuple)
                 ($.default \\parser.types_do_not_match)
                 ($.default \\parser.wrong_parameter)
                 ($.default \\parser.empty_input)
                 ($.default \\parser.unconsumed_input)
                 ($.default \\parser.parameter)
                 ($.default \\parser.recursive_self)
                 ($.default \\parser.recursive_call)

                 ($.documentation \\parser.Env
                   "An environment for type parsing.")

                 ($.documentation (\\parser.Parser it)
                   "A parser of Lux types.")

                 ($.documentation \\parser.fresh
                   "An empty parsing environment.")

                 ($.documentation \\parser.result
                   (format "Applies a parser against a type."
                           \n "Verifies that the parser fully consumes the type's information.")
                   [(result poly type)])

                 ($.documentation \\parser.env
                   "Yields the current parsing environment.")

                 ($.documentation \\parser.next
                   "Inspect a type in the input stream without consuming it.")

                 ($.documentation \\parser.any
                   "Yields a type, without examination.")

                 ($.documentation \\parser.local
                   "Apply a parser to the given inputs."
                   [(local types poly)])

                 ($.documentation \\parser.with_extension
                   ""
                   [(with_extension type poly)])

                 (,, (with_template [<name>]
                       [(`` ($.documentation <name>
                              (format "Parses the contents of a " (,, (template.text [<name>])) " type.")))]

                       [\\parser.variant]
                       [\\parser.tuple]
                       ))

                 ($.documentation \\parser.polymorphic
                   ""
                   [(polymorphic poly)])

                 ($.documentation \\parser.function
                   "Parses a function's inputs and output."
                   [(function in_poly out_poly)])

                 ($.documentation \\parser.applied
                   "Parses a type application."
                   [(applied poly)])

                 (,, (with_template [<name> <doc>]
                       [($.documentation <name>
                          <doc>)]

                       [\\parser.exactly "Parses a type exactly."]
                       [\\parser.sub "Parses a sub type."]
                       [\\parser.super "Parses a super type."]
                       ))

                 ($.documentation \\parser.argument
                   ""
                   [(argument env idx)])

                 ($.documentation \\parser.this_parameter
                   ""
                   [(this_parameter id)])

                 ($.documentation \\parser.existential
                   "Yields an existential type.")

                 ($.documentation \\parser.named
                   "Yields a named type.")

                 ($.documentation \\parser.recursive
                   ""
                   [(recursive poly)])]
                [])))

(`` (.def .public documentation
      (.List $.Module)
      ($.module /._
                "Basic functionality for working with types."
                [($.default /.equivalence)

                 (,, (with_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)])

                 (,, (with_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)])

                 (,, (with_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)])

                 (,, (with_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]
                          (is (Foo a [b c])
                              (is (Foo Bit [Nat Text])
                                  (foo expression)))
                          (is (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]
                          (is (Foo a [b c])
                              (is (Foo Bit [Nat Text])
                                  (foo expression)))
                          (Bar a b c)))
                    "=>"
                    (.type_literal (Bar Bit Nat Text))])

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

                 /primitive.documentation
                 /check.documentation
                 /dynamic.documentation
                 /implicit.documentation
                 /poly.documentation
                 /quotient.documentation
                 /refinement.documentation
                 /resource.documentation
                 /unit.documentation
                 /variance.documentation])))