@grain/stdlib 0.5.13 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +62 -40
  21. package/hash.md +27 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2071 -0
  31. package/json.md +646 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +193 -174
  92. package/runtime/numberUtils.md +29 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +543 -245
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
package/pervasives.gr CHANGED
@@ -1,19 +1,24 @@
1
1
  /**
2
- * @module Pervasives: This module is automatically imported into every Grain program. You can think of it as the global environment. Although it is automatically imported, it can still be imported manually.
2
+ * This module is automatically imported into every Grain program. You can think of it as the global environment. Although it is automatically imported, it can still be imported manually.
3
3
  *
4
- * @example import Pervasives from "pervasives"
4
+ * @example from "pervasives" include Pervasives
5
5
  *
6
6
  * @since v0.1.0
7
7
  */
8
+ @noPervasives
9
+ module Pervasives
8
10
 
9
- import Exception from "runtime/exception"
10
- import Memory from "runtime/unsafe/memory"
11
- import WasmI32 from "runtime/unsafe/wasmi32"
11
+ from "runtime/exception" include Exception
12
+ from "runtime/unsafe/memory" include Memory
13
+ from "runtime/unsafe/wasmi32" include WasmI32
12
14
 
13
- import { equal as (==) } from "runtime/equal"
14
- import { compare } from "runtime/compare"
15
+ from "runtime/equal" include Equal
16
+ use Equal.{ equal as (==) }
17
+ from "runtime/compare" include Compare
18
+ use Compare.{ compare }
15
19
 
16
- import {
20
+ from "runtime/numbers" include Numbers
21
+ use Numbers.{
17
22
  incr,
18
23
  decr,
19
24
  (+),
@@ -21,6 +26,7 @@ import {
21
26
  (*),
22
27
  (/),
23
28
  (%),
29
+ (**),
24
30
  (<),
25
31
  (>),
26
32
  (<=),
@@ -32,56 +38,15 @@ import {
32
38
  (<<),
33
39
  (>>>),
34
40
  (>>),
35
- } from "runtime/numbers"
36
- import { toString, print, concat as (++) } from "runtime/string"
37
-
38
- /**
39
- * @section Types: Type declarations included in the Pervasives module.
40
- */
41
-
42
- /**
43
- * The type of Grain lists.
44
- *
45
- * @example [1, 2, 3]
46
- * @example []
47
- *
48
- * @since v0.1.0
49
- */
50
- export enum List<a> {
51
- [],
52
- [...](a, List<a>),
53
- }
54
-
55
- /**
56
- * Grain's type representing something that may or may not contain data.
57
- * Think of this like a better, type-safe "null".
58
- *
59
- * @since v0.2.0
60
- */
61
- export enum Option<a> {
62
- Some(a),
63
- None,
64
41
  }
65
-
66
- /**
67
- * Grain's type representing the result of something that might error.
68
- *
69
- * @since v0.2.0
70
- */
71
- export enum Result<t, e> {
72
- Ok(t),
73
- Err(e),
74
- }
75
-
76
- /**
77
- * @section Boolean operations: Infix functions for working with Boolean values.
78
- */
42
+ from "runtime/string" include String
43
+ use String.{ toString, print, concat as (++) }
79
44
 
80
45
  /**
81
46
  * Computes the logical NOT (`!`) of the given operand.
82
47
  * Inverts the given Boolean value.
83
48
  *
84
- * @param value: The operand
49
+ * @param bool: The operand
85
50
  * @returns The inverted value
86
51
  *
87
52
  * @example !true // false
@@ -89,7 +54,7 @@ export enum Result<t, e> {
89
54
  *
90
55
  * @since v0.1.0
91
56
  */
92
- export primitive (!): Bool -> Bool = "@not"
57
+ provide primitive (!) = "@not"
93
58
 
94
59
  /**
95
60
  * Computes the logical AND (`&&`) of the given operands.
@@ -97,13 +62,13 @@ export primitive (!): Bool -> Bool = "@not"
97
62
  * If the first operand is `false`, returns `false` without evaluating the second operand.
98
63
  * If the first operand is `true`, returns the value of the second operand.
99
64
  *
100
- * @param value1: The first operand
101
- * @param value2: The second operand
65
+ * @param left: The first operand
66
+ * @param right: The second operand
102
67
  * @returns The first operand if it is `false` or the value of the second operand otherwise
103
68
  *
104
69
  * @since v0.1.0
105
70
  */
106
- export primitive (&&): (Bool, Bool) -> Bool = "@and"
71
+ provide primitive (&&) = "@and"
107
72
 
108
73
  /**
109
74
  * Computes the logical OR `||` of the given operands.
@@ -111,29 +76,15 @@ export primitive (&&): (Bool, Bool) -> Bool = "@and"
111
76
  * If the first operand is `true`, returns `true` without evaluating the second operand.
112
77
  * If the first operand is `false`, returns the value of the second operand.
113
78
  *
114
- * @param value1: The first operand
115
- * @param value2: The second operand
79
+ * @param left: The first operand
80
+ * @param right: The second operand
116
81
  * @returns The first operand if it is `true` or the value of the second operand otherwise
117
82
  *
118
83
  * @since v0.1.0
119
84
  */
120
- export primitive (||): (Bool, Bool) -> Bool = "@or"
121
-
122
- /**
123
- * @section Comparison operations: Infix functions for comparing values.
124
- */
85
+ provide primitive (||) = "@or"
125
86
 
126
- /**
127
- * Check that two values are equal. This checks for structural equality,
128
- * so it also works for comparing things like tuples and lists.
129
- *
130
- * @param value1: The first operand
131
- * @param value2: The second operand
132
- * @returns `true` if the values are structurally equal or `false` otherwise
133
- *
134
- * @since v0.1.0
135
- */
136
- export (==)
87
+ provide { (==) }
137
88
 
138
89
  /**
139
90
  * Check that two values are **not** equal. This checks for structural equality,
@@ -145,19 +96,19 @@ export (==)
145
96
  *
146
97
  * @since v0.2.0
147
98
  */
148
- export let (!=): (a, a) -> Bool = (x, y) => !(x == y)
99
+ provide let (!=) = (value1, value2) => !(value1 == value2)
149
100
 
150
101
  /**
151
102
  * Checks that two values are physically equal.
152
103
  * Use this operator if you don’t need or want structural equality.
153
104
  *
154
- * @param value1: The first operand
155
- * @param value2: The second operand
105
+ * @param left: The first operand
106
+ * @param right: The second operand
156
107
  * @returns `true` if the values are physically equal or `false` otherwise
157
108
  *
158
109
  * @since v0.1.0
159
110
  */
160
- export primitive (is): (a, a) -> Bool = "@is"
111
+ provide primitive (is) = "@is"
161
112
 
162
113
  /**
163
114
  * Checks that two values are **not** physically equal.
@@ -169,294 +120,39 @@ export primitive (is): (a, a) -> Bool = "@is"
169
120
  *
170
121
  * @since v0.2.0
171
122
  */
172
- export let (isnt): (a, a) -> Bool = (x, y) => !(x is y)
173
-
174
- /**
175
- * @section Number comparisons: Infix functions for comparing Number values.
176
- */
177
-
178
- /**
179
- * Checks if the first operand is less than the second operand.
180
- *
181
- * @param num1: The first operand
182
- * @param num2: The second operand
183
- * @returns `true` if the first operand is less than the second operand or `false` otherwise
184
- *
185
- * @since v0.1.0
186
- */
187
- export (<)
188
-
189
- /**
190
- * Checks if the first operand is greater than the second operand.
191
- *
192
- * @param num1: The first operand
193
- * @param num2: The second operand
194
- * @returns `true` if the first operand is greater than the second operand or `false` otherwise
195
- *
196
- * @since v0.1.0
197
- */
198
- export (>)
199
-
200
- /**
201
- * Checks if the first operand is less than or equal to the second operand.
202
- *
203
- * @param num1: The first operand
204
- * @param num2: The second operand
205
- * @returns `true` if the first operand is less than or equal to the second operand or `false` otherwise
206
- *
207
- * @since v0.1.0
208
- */
209
- export (<=)
210
-
211
- /**
212
- * Checks if the first operand is greater than or equal to the second operand.
213
- *
214
- * @param num1: The first operand
215
- * @param num2: The second operand
216
- * @returns `true` if the first operand is greater than or equal to the second operand or `false` otherwise
217
- *
218
- * @since v0.1.0
219
- */
220
- export (>=)
221
-
222
- /**
223
- * Compares the first argument to the second argument and produces an integer result.
224
- * Provides a consistent ordering over all types and is suitable for sorting and other kinds of ordering.
225
- * `compare` treats `NaN` differently than the other comparison operators in that it considers `NaN` equal to itself and smaller than any other number.
226
- *
227
- * @param num1: The first operand
228
- * @param num2: The second operand
229
- * @returns A negative integer if the first operand is less than the second operand, `0` if they are equal, or a positive integer otherwise
230
- *
231
- * @since v0.5.3
232
- */
233
- export compare
234
-
235
- /**
236
- * @section Math operations: Infix functions for working with Number values.
237
- */
238
-
239
- /**
240
- * Computes the sum of its operands.
241
- *
242
- * @param num1: The first operand
243
- * @param num2: The second operand
244
- * @returns The sum of the two operands
245
- *
246
- * @since v0.1.0
247
- */
248
- export (+)
249
-
250
- /**
251
- * Computes the difference of its operands.
252
- *
253
- * @param num1: The first operand
254
- * @param num2: The second operand
255
- * @returns The difference of the two operands
256
- *
257
- * @since v0.1.0
258
- */
259
- export (-)
260
-
261
- /**
262
- * Computes the product of its operands.
263
- *
264
- * @param num1: The first operand
265
- * @param num2: The second operand
266
- * @returns The product of the two operands
267
- *
268
- * @since v0.1.0
269
- */
270
- export (*)
271
-
272
- /**
273
- * Computes the quotient of its operands.
274
- *
275
- * @param num1: The first operand
276
- * @param num2: The second operand
277
- * @returns The quotient of the two operands
278
- *
279
- * @since v0.1.0
280
- */
281
- export (/)
282
-
283
- /**
284
- * Computes the remainder of the division of the first operand by the second.
285
- * The result will have the sign of the second operand.
286
- *
287
- * @param num1: The first operand
288
- * @param num2: The second operand
289
- * @returns The modulus of its operands
290
- *
291
- * @since v0.1.0
292
- */
293
- export (%)
294
-
295
- /**
296
- * Increments the value by one.
297
- *
298
- * @param value: The value to increment
299
- * @returns The incremented value
300
- *
301
- * @since v0.1.0
302
- */
303
- export incr
123
+ provide let (isnt) = (value1, value2) => !(value1 is value2)
304
124
 
305
- /**
306
- * Decrements the value by one.
307
- *
308
- * @param value: The value to decrement
309
- * @returns The decremented value
310
- *
311
- * @since v0.1.0
312
- */
313
- export decr
314
-
315
- /**
316
- * @section String operations: Infix functions for operating on String values.
317
- */
318
-
319
- /**
320
- * Concatenate two strings.
321
- *
322
- * @param str1: The beginning string
323
- * @param str2: The ending string
324
- * @returns The combined string
325
- *
326
- * @example "Foo" ++ "Bar" == "FooBar"
327
- *
328
- * @since v0.2.0
329
- */
330
- export (++)
331
-
332
- /**
333
- * @section Bitwise operations: Infix functions for operating on bits of Number values.
334
- */
335
-
336
- /**
337
- * Computes the bitwise NOT of the operand.
338
- *
339
- * @param value: The operand
340
- * @returns Containing the inverted bits of the operand
341
- *
342
- * @since v0.2.0
343
- */
344
- export lnot
345
-
346
- /**
347
- * Computes the bitwise AND (`&`) on the given operands.
348
- *
349
- * @param value1: The first operand
350
- * @param value2: The second operand
351
- * @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
352
- *
353
- * @since v0.3.0
354
- * @history v0.2.0: Originally named `land`
355
- * @history v0.3.0: Renamed to `&`
356
- */
357
- export (&)
358
-
359
- /**
360
- * Computes the bitwise OR (`|`) on the given operands.
361
- *
362
- * @param value1: The first operand
363
- * @param value2: The second operand
364
- * @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
365
- *
366
- * @since v0.3.0
367
- * @history v0.2.0: Originally named `lor`
368
- * @history v0.3.0: Renamed to `|`
369
- */
370
- export (|)
371
-
372
- /**
373
- * Computes the bitwise XOR (`^`) on the given operands.
374
- *
375
- * @param value1: The first operand
376
- * @param value2: The second operand
377
- * @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
378
- *
379
- * @since v0.3.0
380
- * @history v0.1.0: The `^` operator was originally an alias of `unbox`
381
- * @history v0.2.0: Originally named `lxor`
382
- * @history v0.3.0: Renamed to `^`
383
- */
384
- export (^)
385
-
386
- /**
387
- * Shifts the bits of the value left by the given number of bits.
388
- *
389
- * @param value: The value to shift
390
- * @param amount: The number of bits to shift by
391
- * @returns The shifted value
392
- *
393
- * @since v0.3.0
394
- * @history v0.2.0: Originally named `lsl`
395
- * @history v0.3.0: Renamed to `<<`
396
- */
397
- export (<<)
398
-
399
- /**
400
- * Shifts the bits of the value right by the given number of bits, preserving the sign bit.
401
- *
402
- * @param value: The value to shift
403
- * @param amount: The amount to shift by
404
- * @returns The shifted value
405
- *
406
- * @since v0.3.0
407
- * @history v0.2.0: Originally named `lsr`
408
- * @history v0.3.0: Renamed to `>>>`
409
- */
410
- export (>>>)
411
-
412
- /**
413
- * Shifts the bits of the value right by the given number of bits.
414
- *
415
- * @param value: The value to shift
416
- * @param amount: The amount to shift by
417
- * @returns The shifted value
418
- *
419
- * @since v0.3.0
420
- * @history v0.2.0: Originally named `asr`
421
- * @history v0.3.0: Renamed to `>>`
422
- */
423
- export (>>)
125
+ provide {
126
+ (<),
127
+ (>),
128
+ (<=),
129
+ (>=),
130
+ compare,
131
+ (+),
132
+ (-),
133
+ (*),
134
+ (/),
135
+ (%),
136
+ (**),
137
+ incr,
138
+ decr,
139
+ (++),
140
+ lnot,
141
+ (&),
142
+ (|),
143
+ (^),
144
+ (<<),
145
+ (>>>),
146
+ (>>),
147
+ }
424
148
 
425
149
  // Number coercions & conversions
426
150
 
427
151
  // TODO(#311): Commented until we nail down semantics
428
- // import foreign wasm convertExactToInexact : Number -> Number as inexact from "stdlib-external/runtime"
429
- // import foreign wasm convertInexactToExact : Number -> Number as exact from "stdlib-external/runtime"
152
+ // foreign wasm convertExactToInexact : Number => Number as inexact from "stdlib-external/runtime"
153
+ // foreign wasm convertInexactToExact : Number => Number as exact from "stdlib-external/runtime"
430
154
 
431
- /**
432
- * @section Printing: Functions that deal with printing.
433
- */
434
-
435
- /**
436
- * Converts the given operand to a string.
437
- * Provides a better representation of data types if those types are exported from the module.
438
- *
439
- * @param value: The operand
440
- * @returns The operand, as a string
441
- *
442
- * @since v0.1.0
443
- */
444
- export toString
445
-
446
- /**
447
- * Prints the given operand to the console. Works for any type. Internally, calls `toString`
448
- * on the operand, so a better representation of data type will be printed if those types
449
- * are exported from the module.
450
- *
451
- * @param value: The operand
452
- *
453
- * @since v0.1.0
454
- */
455
- export print
456
-
457
- /**
458
- * @section Type helpers: Functions that help with typechecking.
459
- */
155
+ provide { toString, print }
460
156
 
461
157
  /**
462
158
  * Accepts any value and always returns `void`.
@@ -465,11 +161,7 @@ export print
465
161
  *
466
162
  * @since v0.1.0
467
163
  */
468
- export primitive ignore: a -> Void = "@ignore"
469
-
470
- /**
471
- * @section Assertions: Functions that raise if conditions are not met.
472
- */
164
+ provide primitive ignore = "@ignore"
473
165
 
474
166
  /**
475
167
  * Assert that the given Boolean condition is `true`.
@@ -483,25 +175,21 @@ export primitive ignore: a -> Void = "@ignore"
483
175
  *
484
176
  * @since v0.1.0
485
177
  */
486
- export primitive assert: Bool -> Void = "@assert"
487
-
488
- /**
489
- * @section Failures: Functions that throw an Exception unconditionally.
490
- */
178
+ provide primitive assert = "@assert"
491
179
 
492
180
  // Exceptions
493
- export exception Failure(String)
494
- export exception InvalidArgument(String)
181
+ provide exception Failure(String)
182
+ provide exception InvalidArgument(String)
495
183
 
496
184
  /**
497
185
  * Throw an exception. Currently, exceptions cannot be caught and will crash your program.
498
186
  *
499
- * @param exception: The exception to be thrown
187
+ * @param exn: The exception to be thrown
500
188
  * @returns Anything and nothing—your program won't continue past a throw
501
189
  *
502
190
  * @since v0.3.0
503
191
  */
504
- export primitive throw: Exception -> a = "@throw"
192
+ provide primitive throw = "@throw"
505
193
 
506
194
  /**
507
195
  * Unconditionally throw a `Failure` exception with a message.
@@ -510,11 +198,7 @@ export primitive throw: Exception -> a = "@throw"
510
198
  * @param message: The reason for the failure
511
199
  * @returns Anything and nothing—your program won't continue past a fail expression
512
200
  */
513
- export let fail: String -> a = msg => throw Failure(msg)
514
-
515
- /**
516
- * @section Other: Other functions on values.
517
- */
201
+ provide let fail = message => throw Failure(message)
518
202
 
519
203
  /**
520
204
  * Provides the operand untouched.
@@ -524,63 +208,34 @@ export let fail: String -> a = msg => throw Failure(msg)
524
208
  *
525
209
  * @since v0.2.0
526
210
  */
527
- export let identity = x => x
528
-
529
- /**
530
- * @section Box operations: Functions for working with Box values.
531
- */
211
+ provide let identity = value => value
532
212
 
533
213
  /**
534
214
  * Creates a box containing the given initial value.
535
215
  * Values inside a box can be swapped out with the `:=` operator.
536
216
  * Generally, `let mut` expressions are preferable to using a Box.
537
217
  *
538
- * @param initial: The initial value inside the box
218
+ * @param value: The initial value inside the box
539
219
  * @returns The box containing the initial value
540
220
  *
541
221
  * @since v0.1.0
542
222
  */
543
- export primitive box: a -> Box<a> = "@box"
223
+ provide primitive box = "@box"
544
224
 
545
225
  /**
546
226
  * Retrieves the current value from a box.
547
227
  *
548
- * @param box: The box to unwrap
228
+ * @param value: The box to unwrap
549
229
  * @returns The value inside the box
550
230
  *
551
231
  * @since v0.1.0
552
232
  */
553
- export primitive unbox: Box<a> -> a = "@unbox"
554
-
555
- /**
556
- * @section List operations: Functions for working with List values.
557
- */
558
-
559
- /**
560
- * The list spread syntax (`[a, ...b]`) provided as a function.
561
- *
562
- * @param a: The head of the list
563
- * @param b: The tail of the list
564
- * @returns The new list
565
- *
566
- * @deprecated This will be removed in a future release of Grain.
567
- *
568
- * @since v0.4.0
569
- */
570
- export let cons = (a, b) =>
571
- [a, ...b] // TODO(#802): Remove workaround after 802 is completed
572
- /**
573
- * The empty list syntax (`[]`) provided as a value.
574
- *
575
- * @deprecated This will be removed in a future release of Grain.
576
- *
577
- * @since v0.4.0
578
- */
579
- export let empty = [] // <- for parity with `cons`, but should be deleted as well
233
+ provide primitive unbox = "@unbox"
580
234
 
581
235
  // Setup exception printing
236
+ primitive elideTypeInfo = "@meta.elide_type_info"
582
237
  @unsafe
583
- let rec setupExceptions = () => {
238
+ let setupExceptions = () => {
584
239
  Exception.dangerouslyRegisterPrinter(e => {
585
240
  match (e) {
586
241
  Failure(msg) => Some("Failure: " ++ msg),
@@ -589,7 +244,11 @@ let rec setupExceptions = () => {
589
244
  }
590
245
  })
591
246
 
592
- Exception.dangerouslyRegisterBasePrinter(e => Some(toString(e)))
247
+ // If type information is elided, remove dependency on toString as
248
+ // it will have no effect on exceptions
249
+ if (!elideTypeInfo) {
250
+ Exception.dangerouslyRegisterBasePrinter(e => Some(toString(e)))
251
+ }
593
252
  }
594
253
 
595
254
  setupExceptions()