@magnusopera/fscript 0.80.1 → 0.81.0

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.
@@ -1,21 +1,22 @@
1
1
 
2
2
  import { Span_$reflection, Span, Position } from "./Span.js";
3
- import { iterate as iterate_2, FSharpMap__Add, values, forAll, FSharpMap__get_Keys, keys, FSharpMap__TryFind, ofList, toList, FSharpMap__get_Item, FSharpMap__ContainsKey, FSharpMap__get_Count, exists as exists_1, add, fold as fold_1, remove, map as map_1, tryFind, isEmpty, empty } from "../fable_modules/fable-library-js.5.13.0/Map.js";
4
- import { disposeSafe, getEnumerator, stringHash, compareArrays, equals, comparePrimitives } from "../fable_modules/fable-library-js.5.13.0/Util.js";
3
+ import { iterate as iterate_2, FSharpMap__Add, values, FSharpMap__get_Keys, keys, toList, FSharpMap__get_Item, FSharpMap__get_Count, forAll, FSharpMap__ContainsKey, filter, ofList, exists as exists_1, add, fold as fold_1, remove, map, FSharpMap__TryFind, tryFind, isEmpty, empty } from "../fable_modules/fable-library-js.5.13.0/Map.js";
4
+ import { disposeSafe, getEnumerator, Exception, stringHash, compareArrays, equals, comparePrimitives } from "../fable_modules/fable-library-js.5.13.0/Util.js";
5
5
  import { Types_generalize, Types_freshNumeric, Type_$reflection, Types_freshVar, Types_typeToString, Scheme, Type } from "./Types.js";
6
- import { tryFind as tryFind_1, indexed, ofArray, collect, append, reverse, iterate, tryFindIndex, choose, tail as tail_2, cons, head as head_1, isEmpty as isEmpty_1, empty as empty_2, singleton, zip, length, exists, fold, map } from "../fable_modules/fable-library-js.5.13.0/List.js";
6
+ import { tryFind as tryFind_1, indexed, collect, append, reverse, iterate, tryFindIndex, choose, tail as tail_2, cons, head as head_1, isEmpty as isEmpty_1, empty as empty_2, ofArray, singleton, zip, length, exists, fold, map as map_1 } from "../fable_modules/fable-library-js.5.13.0/List.js";
7
7
  import { toList as toList_2, ofSeq, contains, add as add_1, empty as empty_1, FSharpSet__Add, FSharpSet__Contains } from "../fable_modules/fable-library-js.5.13.0/Set.js";
8
- import { TypeException, TypeError$ } from "./Error.js";
8
+ import { EvalException, TypeException, TypeError$ } from "./Error.js";
9
9
  import { endsWith, split, join, concat, isNullOrWhiteSpace, printf, toText } from "../fable_modules/fable-library-js.5.13.0/String.js";
10
10
  import { defaultArg } from "../fable_modules/fable-library-js.5.13.0/Option.js";
11
11
  import { Union, Record } from "../fable_modules/fable-library-js.5.13.0/Types.js";
12
12
  import { Expr, Ast_spanOfPattern, Ast_spanOfExpr, Pattern_$reflection, TypeDef_$reflection, Expr_$reflection } from "./Ast.js";
13
13
  import { option_type, array_type, union_type, list_type, tuple_type, class_type, bool_type, string_type, record_type } from "../fable_modules/fable-library-js.5.13.0/Reflection.js";
14
- import { foldBack, iterate as iterate_1, filter, map as map_2, toList as toList_1 } from "../fable_modules/fable-library-js.5.13.0/Seq.js";
14
+ import { foldBack, iterate as iterate_1, filter as filter_1, map as map_2, toList as toList_1 } from "../fable_modules/fable-library-js.5.13.0/Seq.js";
15
15
  import { last, item as item_2 } from "../fable_modules/fable-library-js.5.13.0/Array.js";
16
16
  import { distinct } from "../fable_modules/fable-library-js.5.13.0/Seq2.js";
17
17
  import { builtinReservedNames, builtinSchemes } from "./BuiltinSignatures.js";
18
- import { typeDefs as typeDefs_1 } from "./BuiltinTypes.js";
18
+ import { ofExterns, typeDefinitions } from "./HostInterop.js";
19
+ import { typeDefs as typeDefs_2 } from "./BuiltinTypes.js";
19
20
 
20
21
  const unknownSpan = new Span(new Position(undefined, 0, 0), new Position(undefined, 0, 0));
21
22
 
@@ -44,36 +45,40 @@ function applyType(s, t) {
44
45
  v = current.fields[0];
45
46
  break;
46
47
  }
47
- case 5: {
48
+ case 18: {
48
49
  matchResult = 1;
49
50
  break;
50
51
  }
51
- case 6: {
52
+ case 5: {
52
53
  matchResult = 2;
53
54
  break;
54
55
  }
55
- case 7: {
56
+ case 6: {
56
57
  matchResult = 3;
57
58
  break;
58
59
  }
59
- case 8: {
60
+ case 7: {
60
61
  matchResult = 4;
61
62
  break;
62
63
  }
63
- case 9: {
64
+ case 8: {
64
65
  matchResult = 5;
65
66
  break;
66
67
  }
67
- case 10: {
68
+ case 9: {
68
69
  matchResult = 6;
69
70
  break;
70
71
  }
71
- case 11: {
72
+ case 10: {
72
73
  matchResult = 7;
73
74
  break;
74
75
  }
75
- default:
76
+ case 11: {
76
77
  matchResult = 8;
78
+ break;
79
+ }
80
+ default:
81
+ matchResult = 9;
77
82
  }
78
83
  switch (matchResult) {
79
84
  case 0: {
@@ -90,19 +95,61 @@ function applyType(s, t) {
90
95
  return current;
91
96
  }
92
97
  }
93
- case 1:
94
- return new Type(/* TList */ 5, [apply(current.fields[0])]);
98
+ case 1: {
99
+ const id = current.fields[0] | 0;
100
+ const matchValue_1 = FSharpMap__TryFind(s, id);
101
+ let matchResult_1, mappedConstructible_1, mappedFields_1, other_1, mapped_4;
102
+ if (matchValue_1 != null) {
103
+ if (matchValue_1.tag === 18) {
104
+ if ((matchValue_1.fields[1], matchValue_1.fields[2], matchValue_1.fields[0] === id)) {
105
+ matchResult_1 = 0;
106
+ mappedConstructible_1 = matchValue_1.fields[2];
107
+ mappedFields_1 = matchValue_1.fields[1];
108
+ other_1 = matchValue_1.fields[0];
109
+ }
110
+ else if (!equals(matchValue_1, current)) {
111
+ matchResult_1 = 1;
112
+ mapped_4 = matchValue_1;
113
+ }
114
+ else {
115
+ matchResult_1 = 2;
116
+ }
117
+ }
118
+ else if (!equals(matchValue_1, current)) {
119
+ matchResult_1 = 1;
120
+ mapped_4 = matchValue_1;
121
+ }
122
+ else {
123
+ matchResult_1 = 2;
124
+ }
125
+ }
126
+ else {
127
+ matchResult_1 = 2;
128
+ }
129
+ switch (matchResult_1) {
130
+ case 0:
131
+ return new Type(/* TRecordShape */ 18, [id, map((_arg, t_1) => apply(t_1), mappedFields_1), mappedConstructible_1]);
132
+ case 1: {
133
+ current_mut = mapped_4;
134
+ continue apply;
135
+ }
136
+ default:
137
+ return new Type(/* TRecordShape */ 18, [id, map((_arg_1, t_2) => apply(t_2), current.fields[1]), current.fields[2]]);
138
+ }
139
+ }
95
140
  case 2:
96
- return new Type(/* TTask */ 6, [apply(current.fields[0])]);
141
+ return new Type(/* TList */ 5, [apply(current.fields[0])]);
97
142
  case 3:
98
- return new Type(/* TTuple */ 7, [map(apply, current.fields[0])]);
143
+ return new Type(/* TTask */ 6, [apply(current.fields[0])]);
99
144
  case 4:
100
- return new Type(/* TRecord */ 8, [map_1((_arg, t1_2) => apply(t1_2), current.fields[0])]);
145
+ return new Type(/* TTuple */ 7, [map_1(apply, current.fields[0])]);
101
146
  case 5:
102
- return new Type(/* TMap */ 9, [apply(current.fields[0]), apply(current.fields[1])]);
147
+ return new Type(/* TRecord */ 8, [map((_arg_2, t1_2) => apply(t1_2), current.fields[0])]);
103
148
  case 6:
104
- return new Type(/* TOption */ 10, [apply(current.fields[0])]);
149
+ return new Type(/* TMap */ 9, [apply(current.fields[0]), apply(current.fields[1])]);
105
150
  case 7:
151
+ return new Type(/* TOption */ 10, [apply(current.fields[0])]);
152
+ case 8:
106
153
  return new Type(/* TFun */ 11, [apply(current.fields[0]), apply(current.fields[1])]);
107
154
  default:
108
155
  return current;
@@ -130,7 +177,7 @@ function applyEnv(s, env) {
130
177
  return env;
131
178
  }
132
179
  else {
133
- return map_1((_arg, sc) => applyScheme(s, sc), env);
180
+ return map((_arg, sc) => applyScheme(s, sc), env);
134
181
  }
135
182
  }
136
183
 
@@ -142,7 +189,7 @@ function compose(s1, s2) {
142
189
  return s1;
143
190
  }
144
191
  else {
145
- return fold_1((acc, k, v) => add(k, v, acc), s1, map_1((_arg, t) => applyType(s1, t), s2));
192
+ return fold_1((acc, k, v) => add(k, v, acc), s1, map((_arg, t) => applyType(s1, t), s2));
146
193
  }
147
194
  }
148
195
 
@@ -157,10 +204,18 @@ function occurs(v, t) {
157
204
  matchResult = 2;
158
205
  break;
159
206
  }
160
- case 8: {
207
+ case 18: {
161
208
  matchResult = 3;
162
209
  break;
163
210
  }
211
+ case 17: {
212
+ matchResult = 4;
213
+ break;
214
+ }
215
+ case 8: {
216
+ matchResult = 5;
217
+ break;
218
+ }
164
219
  case 0:
165
220
  case 1:
166
221
  case 2:
@@ -169,7 +224,7 @@ function occurs(v, t) {
169
224
  case 12:
170
225
  case 13:
171
226
  case 14: {
172
- matchResult = 5;
227
+ matchResult = 7;
173
228
  break;
174
229
  }
175
230
  case 16: {
@@ -193,13 +248,13 @@ function occurs(v, t) {
193
248
  break;
194
249
  }
195
250
  case 9: {
196
- matchResult = 4;
251
+ matchResult = 6;
197
252
  keyType = current.fields[0];
198
253
  valueType = current.fields[1];
199
254
  break;
200
255
  }
201
256
  case 11: {
202
- matchResult = 4;
257
+ matchResult = 6;
203
258
  keyType = current.fields[0];
204
259
  valueType = current.fields[1];
205
260
  break;
@@ -219,8 +274,17 @@ function occurs(v, t) {
219
274
  case 2:
220
275
  return exists(loop, current.fields[0]);
221
276
  case 3:
222
- return exists_1((_arg, fieldType) => loop(fieldType), current.fields[0]);
277
+ if (current.fields[0] === v) {
278
+ return true;
279
+ }
280
+ else {
281
+ return exists_1((_arg, t_1) => loop(t_1), current.fields[1]);
282
+ }
223
283
  case 4:
284
+ return false;
285
+ case 5:
286
+ return exists_1((_arg_1, fieldType) => loop(fieldType), current.fields[0]);
287
+ case 6:
224
288
  if (loop(keyType)) {
225
289
  return true;
226
290
  }
@@ -242,13 +306,13 @@ function unify(typeDefs, t1, t2, span) {
242
306
  uni:
243
307
  while (true) {
244
308
  const seen = seen_mut, a = a_mut, b = b_mut;
245
- let arg, arg_1, arg_2, arg_3, arg_4, arg_5, arg_6;
309
+ let fields_4, arg, arg_1, arg_2, arg_3, arg_4, arg_5, arg_6;
246
310
  if (FSharpSet__Contains(seen, [a, b]) ? true : FSharpSet__Contains(seen, [b, a])) {
247
311
  return emptySubst;
248
312
  }
249
313
  else {
250
314
  const seen$0027 = FSharpSet__Add(seen, [a, b]);
251
- let matchResult, x_1, y_1, x_2, y_2, x_3, y_3, xs, ys, xf, yf, kx, ky, vx, vy, x_5, y_5, a1, a2, b1, b2, t, v, name_2, t_1, name_3, t_2, v_1, w, concrete, v_2, other_4;
315
+ let matchResult, x_2, y_2, x_3, y_3, x_4, y_4, xs, ys, t, v, id, other, xc, xf, yc, yf, concrete, constructible, id_1, required, x_11, y_11, xf_1, yf_1, kx, ky, vx, vy, x_12, y_12, a1, a2, b1, b2, name_8, t_5, name_9, t_6, v_1, w, concrete_1, v_2, other_5;
252
316
  switch (a.tag) {
253
317
  case 0: {
254
318
  switch (b.tag) {
@@ -257,24 +321,32 @@ function unify(typeDefs, t1, t2, span) {
257
321
  break;
258
322
  }
259
323
  case 15: {
260
- matchResult = 9;
324
+ matchResult = 5;
261
325
  t = a;
262
326
  v = b.fields[0];
263
327
  break;
264
328
  }
329
+ case 18: {
330
+ matchResult = 7;
331
+ concrete = a;
332
+ constructible = b.fields[2];
333
+ id_1 = b.fields[0];
334
+ required = b.fields[1];
335
+ break;
336
+ }
265
337
  case 12: {
266
- matchResult = 11;
267
- name_3 = b.fields[0];
268
- t_2 = a;
338
+ matchResult = 14;
339
+ name_9 = b.fields[0];
340
+ t_6 = a;
269
341
  break;
270
342
  }
271
343
  case 16: {
272
- matchResult = 14;
273
- other_4 = a;
344
+ matchResult = 17;
345
+ other_5 = a;
274
346
  break;
275
347
  }
276
348
  default:
277
- matchResult = 15;
349
+ matchResult = 18;
278
350
  }
279
351
  break;
280
352
  }
@@ -285,25 +357,33 @@ function unify(typeDefs, t1, t2, span) {
285
357
  break;
286
358
  }
287
359
  case 15: {
288
- matchResult = 9;
360
+ matchResult = 5;
289
361
  t = a;
290
362
  v = b.fields[0];
291
363
  break;
292
364
  }
365
+ case 18: {
366
+ matchResult = 7;
367
+ concrete = a;
368
+ constructible = b.fields[2];
369
+ id_1 = b.fields[0];
370
+ required = b.fields[1];
371
+ break;
372
+ }
293
373
  case 12: {
294
- matchResult = 11;
295
- name_3 = b.fields[0];
296
- t_2 = a;
374
+ matchResult = 14;
375
+ name_9 = b.fields[0];
376
+ t_6 = a;
297
377
  break;
298
378
  }
299
379
  case 16: {
300
- matchResult = 13;
301
- concrete = a;
380
+ matchResult = 16;
381
+ concrete_1 = a;
302
382
  v_2 = b.fields[0];
303
383
  break;
304
384
  }
305
385
  default:
306
- matchResult = 15;
386
+ matchResult = 18;
307
387
  }
308
388
  break;
309
389
  }
@@ -314,25 +394,33 @@ function unify(typeDefs, t1, t2, span) {
314
394
  break;
315
395
  }
316
396
  case 15: {
317
- matchResult = 9;
397
+ matchResult = 5;
318
398
  t = a;
319
399
  v = b.fields[0];
320
400
  break;
321
401
  }
402
+ case 18: {
403
+ matchResult = 7;
404
+ concrete = a;
405
+ constructible = b.fields[2];
406
+ id_1 = b.fields[0];
407
+ required = b.fields[1];
408
+ break;
409
+ }
322
410
  case 12: {
323
- matchResult = 11;
324
- name_3 = b.fields[0];
325
- t_2 = a;
411
+ matchResult = 14;
412
+ name_9 = b.fields[0];
413
+ t_6 = a;
326
414
  break;
327
415
  }
328
416
  case 16: {
329
- matchResult = 13;
330
- concrete = a;
417
+ matchResult = 16;
418
+ concrete_1 = a;
331
419
  v_2 = b.fields[0];
332
420
  break;
333
421
  }
334
422
  default:
335
- matchResult = 15;
423
+ matchResult = 18;
336
424
  }
337
425
  break;
338
426
  }
@@ -343,24 +431,32 @@ function unify(typeDefs, t1, t2, span) {
343
431
  break;
344
432
  }
345
433
  case 15: {
346
- matchResult = 9;
434
+ matchResult = 5;
347
435
  t = a;
348
436
  v = b.fields[0];
349
437
  break;
350
438
  }
439
+ case 18: {
440
+ matchResult = 7;
441
+ concrete = a;
442
+ constructible = b.fields[2];
443
+ id_1 = b.fields[0];
444
+ required = b.fields[1];
445
+ break;
446
+ }
351
447
  case 12: {
352
- matchResult = 11;
353
- name_3 = b.fields[0];
354
- t_2 = a;
448
+ matchResult = 14;
449
+ name_9 = b.fields[0];
450
+ t_6 = a;
355
451
  break;
356
452
  }
357
453
  case 16: {
358
- matchResult = 14;
359
- other_4 = a;
454
+ matchResult = 17;
455
+ other_5 = a;
360
456
  break;
361
457
  }
362
458
  default:
363
- matchResult = 15;
459
+ matchResult = 18;
364
460
  }
365
461
  break;
366
462
  }
@@ -371,24 +467,32 @@ function unify(typeDefs, t1, t2, span) {
371
467
  break;
372
468
  }
373
469
  case 15: {
374
- matchResult = 9;
470
+ matchResult = 5;
375
471
  t = a;
376
472
  v = b.fields[0];
377
473
  break;
378
474
  }
475
+ case 18: {
476
+ matchResult = 7;
477
+ concrete = a;
478
+ constructible = b.fields[2];
479
+ id_1 = b.fields[0];
480
+ required = b.fields[1];
481
+ break;
482
+ }
379
483
  case 12: {
380
- matchResult = 11;
381
- name_3 = b.fields[0];
382
- t_2 = a;
484
+ matchResult = 14;
485
+ name_9 = b.fields[0];
486
+ t_6 = a;
383
487
  break;
384
488
  }
385
489
  case 16: {
386
- matchResult = 14;
387
- other_4 = a;
490
+ matchResult = 17;
491
+ other_5 = a;
388
492
  break;
389
493
  }
390
494
  default:
391
- matchResult = 15;
495
+ matchResult = 18;
392
496
  }
393
497
  break;
394
498
  }
@@ -399,24 +503,32 @@ function unify(typeDefs, t1, t2, span) {
399
503
  break;
400
504
  }
401
505
  case 15: {
402
- matchResult = 9;
506
+ matchResult = 5;
403
507
  t = a;
404
508
  v = b.fields[0];
405
509
  break;
406
510
  }
511
+ case 18: {
512
+ matchResult = 7;
513
+ concrete = a;
514
+ constructible = b.fields[2];
515
+ id_1 = b.fields[0];
516
+ required = b.fields[1];
517
+ break;
518
+ }
407
519
  case 12: {
408
- matchResult = 11;
409
- name_3 = b.fields[0];
410
- t_2 = a;
520
+ matchResult = 14;
521
+ name_9 = b.fields[0];
522
+ t_6 = a;
411
523
  break;
412
524
  }
413
525
  case 16: {
414
- matchResult = 14;
415
- other_4 = a;
526
+ matchResult = 17;
527
+ other_5 = a;
416
528
  break;
417
529
  }
418
530
  default:
419
- matchResult = 15;
531
+ matchResult = 18;
420
532
  }
421
533
  break;
422
534
  }
@@ -425,32 +537,40 @@ function unify(typeDefs, t1, t2, span) {
425
537
  case 12: {
426
538
  if (a.fields[0] === b.fields[0]) {
427
539
  matchResult = 1;
428
- x_1 = a.fields[0];
429
- y_1 = b.fields[0];
540
+ x_2 = a.fields[0];
541
+ y_2 = b.fields[0];
430
542
  }
431
543
  else {
432
- matchResult = 10;
433
- name_2 = a.fields[0];
434
- t_1 = b;
544
+ matchResult = 13;
545
+ name_8 = a.fields[0];
546
+ t_5 = b;
435
547
  }
436
548
  break;
437
549
  }
438
550
  case 15: {
439
- matchResult = 9;
551
+ matchResult = 5;
440
552
  t = a;
441
553
  v = b.fields[0];
442
554
  break;
443
555
  }
556
+ case 18: {
557
+ matchResult = 7;
558
+ concrete = a;
559
+ constructible = b.fields[2];
560
+ id_1 = b.fields[0];
561
+ required = b.fields[1];
562
+ break;
563
+ }
444
564
  case 16: {
445
- matchResult = 10;
446
- name_2 = a.fields[0];
447
- t_1 = b;
565
+ matchResult = 13;
566
+ name_8 = a.fields[0];
567
+ t_5 = b;
448
568
  break;
449
569
  }
450
570
  default: {
451
- matchResult = 10;
452
- name_2 = a.fields[0];
453
- t_1 = b;
571
+ matchResult = 13;
572
+ name_8 = a.fields[0];
573
+ t_5 = b;
454
574
  }
455
575
  }
456
576
  break;
@@ -459,29 +579,37 @@ function unify(typeDefs, t1, t2, span) {
459
579
  switch (b.tag) {
460
580
  case 5: {
461
581
  matchResult = 2;
462
- x_2 = a.fields[0];
463
- y_2 = b.fields[0];
582
+ x_3 = a.fields[0];
583
+ y_3 = b.fields[0];
464
584
  break;
465
585
  }
466
586
  case 15: {
467
- matchResult = 9;
587
+ matchResult = 5;
468
588
  t = a;
469
589
  v = b.fields[0];
470
590
  break;
471
591
  }
592
+ case 18: {
593
+ matchResult = 7;
594
+ concrete = a;
595
+ constructible = b.fields[2];
596
+ id_1 = b.fields[0];
597
+ required = b.fields[1];
598
+ break;
599
+ }
472
600
  case 12: {
473
- matchResult = 11;
474
- name_3 = b.fields[0];
475
- t_2 = a;
601
+ matchResult = 14;
602
+ name_9 = b.fields[0];
603
+ t_6 = a;
476
604
  break;
477
605
  }
478
606
  case 16: {
479
- matchResult = 14;
480
- other_4 = a;
607
+ matchResult = 17;
608
+ other_5 = a;
481
609
  break;
482
610
  }
483
611
  default:
484
- matchResult = 15;
612
+ matchResult = 18;
485
613
  }
486
614
  break;
487
615
  }
@@ -489,29 +617,37 @@ function unify(typeDefs, t1, t2, span) {
489
617
  switch (b.tag) {
490
618
  case 6: {
491
619
  matchResult = 3;
492
- x_3 = a.fields[0];
493
- y_3 = b.fields[0];
620
+ x_4 = a.fields[0];
621
+ y_4 = b.fields[0];
494
622
  break;
495
623
  }
496
624
  case 15: {
497
- matchResult = 9;
625
+ matchResult = 5;
498
626
  t = a;
499
627
  v = b.fields[0];
500
628
  break;
501
629
  }
630
+ case 18: {
631
+ matchResult = 7;
632
+ concrete = a;
633
+ constructible = b.fields[2];
634
+ id_1 = b.fields[0];
635
+ required = b.fields[1];
636
+ break;
637
+ }
502
638
  case 12: {
503
- matchResult = 11;
504
- name_3 = b.fields[0];
505
- t_2 = a;
639
+ matchResult = 14;
640
+ name_9 = b.fields[0];
641
+ t_6 = a;
506
642
  break;
507
643
  }
508
644
  case 16: {
509
- matchResult = 14;
510
- other_4 = a;
645
+ matchResult = 17;
646
+ other_5 = a;
511
647
  break;
512
648
  }
513
649
  default:
514
- matchResult = 15;
650
+ matchResult = 18;
515
651
  }
516
652
  break;
517
653
  }
@@ -524,192 +660,327 @@ function unify(typeDefs, t1, t2, span) {
524
660
  break;
525
661
  }
526
662
  case 15: {
527
- matchResult = 9;
663
+ matchResult = 5;
528
664
  t = a;
529
665
  v = b.fields[0];
530
666
  break;
531
667
  }
668
+ case 18: {
669
+ matchResult = 7;
670
+ concrete = a;
671
+ constructible = b.fields[2];
672
+ id_1 = b.fields[0];
673
+ required = b.fields[1];
674
+ break;
675
+ }
532
676
  case 12: {
533
- matchResult = 11;
534
- name_3 = b.fields[0];
535
- t_2 = a;
677
+ matchResult = 14;
678
+ name_9 = b.fields[0];
679
+ t_6 = a;
536
680
  break;
537
681
  }
538
682
  case 16: {
539
- matchResult = 14;
540
- other_4 = a;
683
+ matchResult = 17;
684
+ other_5 = a;
541
685
  break;
542
686
  }
543
687
  default:
544
- matchResult = 15;
688
+ matchResult = 18;
545
689
  }
546
690
  break;
547
691
  }
548
- case 8: {
692
+ case 15: {
693
+ matchResult = 5;
694
+ t = b;
695
+ v = a.fields[0];
696
+ break;
697
+ }
698
+ case 18: {
549
699
  switch (b.tag) {
550
- case 8: {
700
+ case 15: {
551
701
  matchResult = 5;
552
- xf = a.fields[0];
553
- yf = b.fields[0];
702
+ t = a;
703
+ v = b.fields[0];
704
+ break;
705
+ }
706
+ case 18: {
707
+ matchResult = 6;
708
+ id = a.fields[0];
709
+ other = b.fields[0];
710
+ xc = a.fields[2];
711
+ xf = a.fields[1];
712
+ yc = b.fields[2];
713
+ yf = b.fields[1];
714
+ break;
715
+ }
716
+ case 12: {
717
+ matchResult = 7;
718
+ concrete = b;
719
+ constructible = a.fields[2];
720
+ id_1 = a.fields[0];
721
+ required = a.fields[1];
554
722
  break;
555
723
  }
724
+ case 16: {
725
+ matchResult = 7;
726
+ concrete = b;
727
+ constructible = a.fields[2];
728
+ id_1 = a.fields[0];
729
+ required = a.fields[1];
730
+ break;
731
+ }
732
+ default: {
733
+ matchResult = 7;
734
+ concrete = b;
735
+ constructible = a.fields[2];
736
+ id_1 = a.fields[0];
737
+ required = a.fields[1];
738
+ }
739
+ }
740
+ break;
741
+ }
742
+ case 17: {
743
+ switch (b.tag) {
556
744
  case 15: {
557
- matchResult = 9;
745
+ matchResult = 5;
558
746
  t = a;
559
747
  v = b.fields[0];
560
748
  break;
561
749
  }
750
+ case 18: {
751
+ matchResult = 7;
752
+ concrete = a;
753
+ constructible = b.fields[2];
754
+ id_1 = b.fields[0];
755
+ required = b.fields[1];
756
+ break;
757
+ }
758
+ case 17: {
759
+ if (a.fields[0] === b.fields[0]) {
760
+ matchResult = 8;
761
+ x_11 = a.fields[0];
762
+ y_11 = b.fields[0];
763
+ }
764
+ else {
765
+ matchResult = 18;
766
+ }
767
+ break;
768
+ }
562
769
  case 12: {
563
- matchResult = 11;
564
- name_3 = b.fields[0];
565
- t_2 = a;
770
+ matchResult = 14;
771
+ name_9 = b.fields[0];
772
+ t_6 = a;
566
773
  break;
567
774
  }
568
775
  case 16: {
776
+ matchResult = 17;
777
+ other_5 = a;
778
+ break;
779
+ }
780
+ default:
781
+ matchResult = 18;
782
+ }
783
+ break;
784
+ }
785
+ case 8: {
786
+ switch (b.tag) {
787
+ case 15: {
788
+ matchResult = 5;
789
+ t = a;
790
+ v = b.fields[0];
791
+ break;
792
+ }
793
+ case 18: {
794
+ matchResult = 7;
795
+ concrete = a;
796
+ constructible = b.fields[2];
797
+ id_1 = b.fields[0];
798
+ required = b.fields[1];
799
+ break;
800
+ }
801
+ case 8: {
802
+ matchResult = 9;
803
+ xf_1 = a.fields[0];
804
+ yf_1 = b.fields[0];
805
+ break;
806
+ }
807
+ case 12: {
569
808
  matchResult = 14;
570
- other_4 = a;
809
+ name_9 = b.fields[0];
810
+ t_6 = a;
811
+ break;
812
+ }
813
+ case 16: {
814
+ matchResult = 17;
815
+ other_5 = a;
571
816
  break;
572
817
  }
573
818
  default:
574
- matchResult = 15;
819
+ matchResult = 18;
575
820
  }
576
821
  break;
577
822
  }
578
823
  case 9: {
579
824
  switch (b.tag) {
825
+ case 15: {
826
+ matchResult = 5;
827
+ t = a;
828
+ v = b.fields[0];
829
+ break;
830
+ }
831
+ case 18: {
832
+ matchResult = 7;
833
+ concrete = a;
834
+ constructible = b.fields[2];
835
+ id_1 = b.fields[0];
836
+ required = b.fields[1];
837
+ break;
838
+ }
580
839
  case 9: {
581
- matchResult = 6;
840
+ matchResult = 10;
582
841
  kx = a.fields[0];
583
842
  ky = b.fields[0];
584
843
  vx = a.fields[1];
585
844
  vy = b.fields[1];
586
845
  break;
587
846
  }
588
- case 15: {
589
- matchResult = 9;
590
- t = a;
591
- v = b.fields[0];
592
- break;
593
- }
594
847
  case 12: {
595
- matchResult = 11;
596
- name_3 = b.fields[0];
597
- t_2 = a;
848
+ matchResult = 14;
849
+ name_9 = b.fields[0];
850
+ t_6 = a;
598
851
  break;
599
852
  }
600
853
  case 16: {
601
- matchResult = 14;
602
- other_4 = a;
854
+ matchResult = 17;
855
+ other_5 = a;
603
856
  break;
604
857
  }
605
858
  default:
606
- matchResult = 15;
859
+ matchResult = 18;
607
860
  }
608
861
  break;
609
862
  }
610
863
  case 10: {
611
864
  switch (b.tag) {
612
- case 10: {
613
- matchResult = 7;
614
- x_5 = a.fields[0];
615
- y_5 = b.fields[0];
616
- break;
617
- }
618
865
  case 15: {
619
- matchResult = 9;
866
+ matchResult = 5;
620
867
  t = a;
621
868
  v = b.fields[0];
622
869
  break;
623
870
  }
624
- case 12: {
871
+ case 18: {
872
+ matchResult = 7;
873
+ concrete = a;
874
+ constructible = b.fields[2];
875
+ id_1 = b.fields[0];
876
+ required = b.fields[1];
877
+ break;
878
+ }
879
+ case 10: {
625
880
  matchResult = 11;
626
- name_3 = b.fields[0];
627
- t_2 = a;
881
+ x_12 = a.fields[0];
882
+ y_12 = b.fields[0];
628
883
  break;
629
884
  }
630
- case 16: {
885
+ case 12: {
631
886
  matchResult = 14;
632
- other_4 = a;
887
+ name_9 = b.fields[0];
888
+ t_6 = a;
889
+ break;
890
+ }
891
+ case 16: {
892
+ matchResult = 17;
893
+ other_5 = a;
633
894
  break;
634
895
  }
635
896
  default:
636
- matchResult = 15;
897
+ matchResult = 18;
637
898
  }
638
899
  break;
639
900
  }
640
901
  case 11: {
641
902
  switch (b.tag) {
903
+ case 15: {
904
+ matchResult = 5;
905
+ t = a;
906
+ v = b.fields[0];
907
+ break;
908
+ }
909
+ case 18: {
910
+ matchResult = 7;
911
+ concrete = a;
912
+ constructible = b.fields[2];
913
+ id_1 = b.fields[0];
914
+ required = b.fields[1];
915
+ break;
916
+ }
642
917
  case 11: {
643
- matchResult = 8;
918
+ matchResult = 12;
644
919
  a1 = a.fields[0];
645
920
  a2 = b.fields[0];
646
921
  b1 = a.fields[1];
647
922
  b2 = b.fields[1];
648
923
  break;
649
924
  }
650
- case 15: {
651
- matchResult = 9;
652
- t = a;
653
- v = b.fields[0];
654
- break;
655
- }
656
925
  case 12: {
657
- matchResult = 11;
658
- name_3 = b.fields[0];
659
- t_2 = a;
926
+ matchResult = 14;
927
+ name_9 = b.fields[0];
928
+ t_6 = a;
660
929
  break;
661
930
  }
662
931
  case 16: {
663
- matchResult = 14;
664
- other_4 = a;
932
+ matchResult = 17;
933
+ other_5 = a;
665
934
  break;
666
935
  }
667
936
  default:
668
- matchResult = 15;
937
+ matchResult = 18;
669
938
  }
670
939
  break;
671
940
  }
672
- case 15: {
673
- matchResult = 9;
674
- t = b;
675
- v = a.fields[0];
676
- break;
677
- }
678
941
  case 16: {
679
942
  switch (b.tag) {
680
943
  case 15: {
681
- matchResult = 9;
944
+ matchResult = 5;
682
945
  t = a;
683
946
  v = b.fields[0];
684
947
  break;
685
948
  }
949
+ case 18: {
950
+ matchResult = 7;
951
+ concrete = a;
952
+ constructible = b.fields[2];
953
+ id_1 = b.fields[0];
954
+ required = b.fields[1];
955
+ break;
956
+ }
686
957
  case 12: {
687
- matchResult = 11;
688
- name_3 = b.fields[0];
689
- t_2 = a;
958
+ matchResult = 14;
959
+ name_9 = b.fields[0];
960
+ t_6 = a;
690
961
  break;
691
962
  }
692
963
  case 16: {
693
- matchResult = 12;
964
+ matchResult = 15;
694
965
  v_1 = a.fields[0];
695
966
  w = b.fields[0];
696
967
  break;
697
968
  }
698
969
  case 1: {
699
- matchResult = 13;
700
- concrete = b;
970
+ matchResult = 16;
971
+ concrete_1 = b;
701
972
  v_2 = a.fields[0];
702
973
  break;
703
974
  }
704
975
  case 2: {
705
- matchResult = 13;
706
- concrete = b;
976
+ matchResult = 16;
977
+ concrete_1 = b;
707
978
  v_2 = a.fields[0];
708
979
  break;
709
980
  }
710
981
  default: {
711
- matchResult = 14;
712
- other_4 = b;
982
+ matchResult = 17;
983
+ other_5 = b;
713
984
  }
714
985
  }
715
986
  break;
@@ -717,24 +988,32 @@ function unify(typeDefs, t1, t2, span) {
717
988
  default:
718
989
  switch (b.tag) {
719
990
  case 15: {
720
- matchResult = 9;
991
+ matchResult = 5;
721
992
  t = a;
722
993
  v = b.fields[0];
723
994
  break;
724
995
  }
996
+ case 18: {
997
+ matchResult = 7;
998
+ concrete = a;
999
+ constructible = b.fields[2];
1000
+ id_1 = b.fields[0];
1001
+ required = b.fields[1];
1002
+ break;
1003
+ }
725
1004
  case 12: {
726
- matchResult = 11;
727
- name_3 = b.fields[0];
728
- t_2 = a;
1005
+ matchResult = 14;
1006
+ name_9 = b.fields[0];
1007
+ t_6 = a;
729
1008
  break;
730
1009
  }
731
1010
  case 16: {
732
- matchResult = 14;
733
- other_4 = a;
1011
+ matchResult = 17;
1012
+ other_5 = a;
734
1013
  break;
735
1014
  }
736
1015
  default:
737
- matchResult = 15;
1016
+ matchResult = 18;
738
1017
  }
739
1018
  }
740
1019
  switch (matchResult) {
@@ -744,14 +1023,14 @@ function unify(typeDefs, t1, t2, span) {
744
1023
  return emptySubst;
745
1024
  case 2: {
746
1025
  seen_mut = seen$0027;
747
- a_mut = x_2;
748
- b_mut = y_2;
1026
+ a_mut = x_3;
1027
+ b_mut = y_3;
749
1028
  continue uni;
750
1029
  }
751
1030
  case 3: {
752
1031
  seen_mut = seen$0027;
753
- a_mut = x_3;
754
- b_mut = y_3;
1032
+ a_mut = x_4;
1033
+ b_mut = y_4;
755
1034
  continue uni;
756
1035
  }
757
1036
  case 4: {
@@ -760,11 +1039,130 @@ function unify(typeDefs, t1, t2, span) {
760
1039
  }
761
1040
  return fold((sAcc, tupledArg) => compose(uni(seen$0027, applyType(sAcc, tupledArg[0]), applyType(sAcc, tupledArg[1])), sAcc), emptySubst, zip(xs, ys));
762
1041
  }
763
- case 5: {
764
- const patternInput = (FSharpMap__get_Count(xf) <= FSharpMap__get_Count(yf)) ? [xf, yf] : [yf, xf];
1042
+ case 5:
1043
+ if (equals(t, new Type(/* TVar */ 15, [v]))) {
1044
+ return emptySubst;
1045
+ }
1046
+ else if (equals(t, new Type(/* TNumeric */ 16, [v]))) {
1047
+ return ofList(singleton([v, t]), {
1048
+ Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
1049
+ });
1050
+ }
1051
+ else if (occurs(v, t)) {
1052
+ throw new TypeException(new TypeError$("Occurs check failed", span));
1053
+ }
1054
+ else {
1055
+ return ofList(singleton([v, t]), {
1056
+ Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
1057
+ });
1058
+ }
1059
+ case 6: {
1060
+ const shared = filter((name, _arg) => FSharpMap__ContainsKey(yf, name), xf);
1061
+ const s = uni(seen$0027, new Type(/* TRecord */ 8, [shared]), new Type(/* TRecord */ 8, [filter((name_1, _arg_1) => FSharpMap__ContainsKey(shared, name_1), yf)]));
1062
+ const fields = map((_arg_2, t_2) => applyType(s, t_2), fold_1((acc, name_2, t_1) => add(name_2, t_1, acc), xf, yf));
1063
+ if (exists_1((_arg_3, t_3) => {
1064
+ if (occurs(id, t_3)) {
1065
+ return true;
1066
+ }
1067
+ else {
1068
+ return occurs(other, t_3);
1069
+ }
1070
+ }, fields)) {
1071
+ throw new TypeException(new TypeError$("Occurs check failed", span));
1072
+ }
1073
+ const merged = new Type(/* TRecordShape */ 18, [other, fields, xc ? true : yc]);
1074
+ return compose((id === other) ? ofList(singleton([other, merged]), {
1075
+ Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
1076
+ }) : ofList(ofArray([[id, merged], [other, merged]]), {
1077
+ Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
1078
+ }), s);
1079
+ }
1080
+ case 7: {
1081
+ const fieldsOf = (t_4_mut) => {
1082
+ fieldsOf:
1083
+ while (true) {
1084
+ const t_4 = t_4_mut;
1085
+ let matchResult_1, name_3, fields_2, fields_3;
1086
+ switch (t_4.tag) {
1087
+ case 12: {
1088
+ matchResult_1 = 0;
1089
+ name_3 = t_4.fields[0];
1090
+ break;
1091
+ }
1092
+ case 8: {
1093
+ matchResult_1 = 1;
1094
+ fields_2 = t_4.fields[0];
1095
+ break;
1096
+ }
1097
+ case 17: {
1098
+ if (!constructible) {
1099
+ matchResult_1 = 2;
1100
+ fields_3 = t_4.fields[1];
1101
+ }
1102
+ else {
1103
+ matchResult_1 = 3;
1104
+ }
1105
+ break;
1106
+ }
1107
+ default:
1108
+ matchResult_1 = 3;
1109
+ }
1110
+ switch (matchResult_1) {
1111
+ case 0: {
1112
+ const option_1 = FSharpMap__TryFind(typeDefs, name_3);
1113
+ if (option_1 != null) {
1114
+ t_4_mut = option_1;
1115
+ continue fieldsOf;
1116
+ }
1117
+ else {
1118
+ return undefined;
1119
+ }
1120
+ }
1121
+ case 1:
1122
+ return fields_2;
1123
+ case 2:
1124
+ return fields_3;
1125
+ default:
1126
+ return undefined;
1127
+ }
1128
+ break;
1129
+ }
1130
+ };
1131
+ if (occurs(id_1, concrete)) {
1132
+ throw new TypeException(new TypeError$("Occurs check failed", span));
1133
+ }
1134
+ const matchValue_1 = fieldsOf(concrete);
1135
+ let matchResult_2, fields_5;
1136
+ if (matchValue_1 != null) {
1137
+ if ((fields_4 = matchValue_1, forAll((name_4, _arg_4) => FSharpMap__ContainsKey(fields_4, name_4), required))) {
1138
+ matchResult_2 = 0;
1139
+ fields_5 = matchValue_1;
1140
+ }
1141
+ else {
1142
+ matchResult_2 = 1;
1143
+ }
1144
+ }
1145
+ else {
1146
+ matchResult_2 = 1;
1147
+ }
1148
+ switch (matchResult_2) {
1149
+ case 0: {
1150
+ const s_1 = uni(seen$0027, new Type(/* TRecord */ 8, [required]), new Type(/* TRecord */ 8, [filter((name_5, _arg_5) => FSharpMap__ContainsKey(required, name_5), fields_5)]));
1151
+ return compose(ofList(singleton([id_1, applyType(s_1, concrete)]), {
1152
+ Compare: (x_10, y_10) => (comparePrimitives(x_10, y_10) | 0),
1153
+ }), s_1);
1154
+ }
1155
+ default:
1156
+ throw new TypeException(new TypeError$("Record constraint requires compatible fields and a constructible value for updates", span));
1157
+ }
1158
+ }
1159
+ case 8:
1160
+ return emptySubst;
1161
+ case 9: {
1162
+ const patternInput = (FSharpMap__get_Count(xf_1) <= FSharpMap__get_Count(yf_1)) ? [xf_1, yf_1] : [yf_1, xf_1];
765
1163
  const otherFields = patternInput[1];
766
1164
  const fieldsToCheck = patternInput[0];
767
- if (exists_1((name, _arg) => !FSharpMap__ContainsKey(otherFields, name), fieldsToCheck)) {
1165
+ if (exists_1((name_6, _arg_6) => !FSharpMap__ContainsKey(otherFields, name_6), fieldsToCheck)) {
768
1166
  throw new TypeException(new TypeError$("Record field set mismatch", span));
769
1167
  }
770
1168
  return fold((sAcc_1, tupledArg_1) => {
@@ -772,74 +1170,57 @@ function unify(typeDefs, t1, t2, span) {
772
1170
  return compose(uni(seen$0027, applyType(sAcc_1, tupledArg_1[1]), applyType(sAcc_1, yt)), sAcc_1);
773
1171
  }, emptySubst, toList(fieldsToCheck));
774
1172
  }
775
- case 6: {
1173
+ case 10: {
776
1174
  const s1_2 = uni(seen$0027, kx, ky);
777
1175
  return compose(uni(seen$0027, applyType(s1_2, vx), applyType(s1_2, vy)), s1_2);
778
1176
  }
779
- case 7: {
1177
+ case 11: {
780
1178
  seen_mut = seen$0027;
781
- a_mut = x_5;
782
- b_mut = y_5;
1179
+ a_mut = x_12;
1180
+ b_mut = y_12;
783
1181
  continue uni;
784
1182
  }
785
- case 8: {
1183
+ case 12: {
786
1184
  const s1_3 = uni(seen$0027, a1, a2);
787
1185
  return compose(uni(seen$0027, applyType(s1_3, b1), applyType(s1_3, b2)), s1_3);
788
1186
  }
789
- case 9:
790
- if (equals(t, new Type(/* TVar */ 15, [v]))) {
791
- return emptySubst;
792
- }
793
- else if (equals(t, new Type(/* TNumeric */ 16, [v]))) {
794
- return ofList(singleton([v, t]), {
795
- Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
796
- });
797
- }
798
- else if (occurs(v, t)) {
799
- throw new TypeException(new TypeError$("Occurs check failed", span));
800
- }
801
- else {
802
- return ofList(singleton([v, t]), {
803
- Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
804
- });
805
- }
806
- case 10: {
807
- const matchValue_1 = FSharpMap__TryFind(typeDefs, name_2);
808
- let matchResult_1, expanded_1;
809
- if (matchValue_1 != null) {
810
- if (!equals(matchValue_1, new Type(/* TNamed */ 12, [name_2]))) {
811
- matchResult_1 = 0;
812
- expanded_1 = matchValue_1;
1187
+ case 13: {
1188
+ const matchValue_2 = FSharpMap__TryFind(typeDefs, name_8);
1189
+ let matchResult_3, expanded_1;
1190
+ if (matchValue_2 != null) {
1191
+ if (!equals(matchValue_2, new Type(/* TNamed */ 12, [name_8]))) {
1192
+ matchResult_3 = 0;
1193
+ expanded_1 = matchValue_2;
813
1194
  }
814
1195
  else {
815
- matchResult_1 = 1;
1196
+ matchResult_3 = 1;
816
1197
  }
817
1198
  }
818
1199
  else {
819
- matchResult_1 = 1;
1200
+ matchResult_3 = 1;
820
1201
  }
821
- switch (matchResult_1) {
1202
+ switch (matchResult_3) {
822
1203
  case 0: {
823
1204
  seen_mut = seen$0027;
824
1205
  a_mut = expanded_1;
825
- b_mut = t_1;
1206
+ b_mut = t_5;
826
1207
  continue uni;
827
1208
  }
828
1209
  default: {
829
- let matchResult_2, other_1;
830
- if (t_1.tag === 12) {
831
- if (t_1.fields[0] === name_2) {
832
- matchResult_2 = 0;
833
- other_1 = t_1.fields[0];
1210
+ let matchResult_4, other_2;
1211
+ if (t_5.tag === 12) {
1212
+ if (t_5.fields[0] === name_8) {
1213
+ matchResult_4 = 0;
1214
+ other_2 = t_5.fields[0];
834
1215
  }
835
1216
  else {
836
- matchResult_2 = 1;
1217
+ matchResult_4 = 1;
837
1218
  }
838
1219
  }
839
1220
  else {
840
- matchResult_2 = 1;
1221
+ matchResult_4 = 1;
841
1222
  }
842
- switch (matchResult_2) {
1223
+ switch (matchResult_4) {
843
1224
  case 0:
844
1225
  return emptySubst;
845
1226
  default:
@@ -848,43 +1229,43 @@ function unify(typeDefs, t1, t2, span) {
848
1229
  }
849
1230
  }
850
1231
  }
851
- case 11: {
852
- const matchValue_2 = FSharpMap__TryFind(typeDefs, name_3);
853
- let matchResult_3, expanded_3;
854
- if (matchValue_2 != null) {
855
- if (!equals(matchValue_2, new Type(/* TNamed */ 12, [name_3]))) {
856
- matchResult_3 = 0;
857
- expanded_3 = matchValue_2;
1232
+ case 14: {
1233
+ const matchValue_3 = FSharpMap__TryFind(typeDefs, name_9);
1234
+ let matchResult_5, expanded_3;
1235
+ if (matchValue_3 != null) {
1236
+ if (!equals(matchValue_3, new Type(/* TNamed */ 12, [name_9]))) {
1237
+ matchResult_5 = 0;
1238
+ expanded_3 = matchValue_3;
858
1239
  }
859
1240
  else {
860
- matchResult_3 = 1;
1241
+ matchResult_5 = 1;
861
1242
  }
862
1243
  }
863
1244
  else {
864
- matchResult_3 = 1;
1245
+ matchResult_5 = 1;
865
1246
  }
866
- switch (matchResult_3) {
1247
+ switch (matchResult_5) {
867
1248
  case 0: {
868
1249
  seen_mut = seen$0027;
869
- a_mut = t_2;
1250
+ a_mut = t_6;
870
1251
  b_mut = expanded_3;
871
1252
  continue uni;
872
1253
  }
873
1254
  default: {
874
- let matchResult_4, other_3;
875
- if (t_2.tag === 12) {
876
- if (t_2.fields[0] === name_3) {
877
- matchResult_4 = 0;
878
- other_3 = t_2.fields[0];
1255
+ let matchResult_6, other_4;
1256
+ if (t_6.tag === 12) {
1257
+ if (t_6.fields[0] === name_9) {
1258
+ matchResult_6 = 0;
1259
+ other_4 = t_6.fields[0];
879
1260
  }
880
1261
  else {
881
- matchResult_4 = 1;
1262
+ matchResult_6 = 1;
882
1263
  }
883
1264
  }
884
1265
  else {
885
- matchResult_4 = 1;
1266
+ matchResult_6 = 1;
886
1267
  }
887
- switch (matchResult_4) {
1268
+ switch (matchResult_6) {
888
1269
  case 0:
889
1270
  return emptySubst;
890
1271
  default:
@@ -893,21 +1274,21 @@ function unify(typeDefs, t1, t2, span) {
893
1274
  }
894
1275
  }
895
1276
  }
896
- case 12:
1277
+ case 15:
897
1278
  if (v_1 === w) {
898
1279
  return emptySubst;
899
1280
  }
900
1281
  else {
901
1282
  return ofList(singleton([v_1, new Type(/* TNumeric */ 16, [w])]), {
902
- Compare: (x_8, y_8) => (comparePrimitives(x_8, y_8) | 0),
1283
+ Compare: (x_13, y_13) => (comparePrimitives(x_13, y_13) | 0),
903
1284
  });
904
1285
  }
905
- case 13:
906
- return ofList(singleton([v_2, concrete]), {
907
- Compare: (x_9, y_9) => (comparePrimitives(x_9, y_9) | 0),
1286
+ case 16:
1287
+ return ofList(singleton([v_2, concrete_1]), {
1288
+ Compare: (x_14, y_14) => (comparePrimitives(x_14, y_14) | 0),
908
1289
  });
909
- case 14:
910
- throw new TypeException(new TypeError$((arg_4 = Types_typeToString(other_4), toText(printf("Expected numeric type, got %s"))(arg_4)), span));
1290
+ case 17:
1291
+ throw new TypeException(new TypeError$((arg_4 = Types_typeToString(other_5), toText(printf("Expected numeric type, got %s"))(arg_4)), span));
911
1292
  default:
912
1293
  throw new TypeException(new TypeError$((arg_5 = Types_typeToString(a), (arg_6 = Types_typeToString(b), toText(printf("Type mismatch: %s vs %s"))(arg_5)(arg_6))), span));
913
1294
  }
@@ -916,15 +1297,16 @@ function unify(typeDefs, t1, t2, span) {
916
1297
  }
917
1298
  };
918
1299
  return uni(empty_1({
919
- Compare: (x_10, y_10) => (compareArrays(x_10, y_10) | 0),
1300
+ Compare: (x_15, y_15) => (compareArrays(x_15, y_15) | 0),
920
1301
  }), t1, t2);
921
1302
  }
922
1303
 
923
1304
  function instantiate(_arg) {
924
- const freshMap = ofList(map((v) => [v, Types_freshVar()], _arg.fields[0]), {
1305
+ const freshMap = ofList(map_1((v) => [v, Types_freshVar()], _arg.fields[0]), {
925
1306
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
926
1307
  });
927
1308
  const subst = (t_1) => {
1309
+ let matchValue_1, v_3;
928
1310
  switch (t_1.tag) {
929
1311
  case 15:
930
1312
  return defaultArg(tryFind(t_1.fields[0], freshMap), t_1);
@@ -950,14 +1332,18 @@ function instantiate(_arg) {
950
1332
  return t_1;
951
1333
  }
952
1334
  }
1335
+ case 18: {
1336
+ const id = t_1.fields[0] | 0;
1337
+ return new Type(/* TRecordShape */ 18, [(matchValue_1 = FSharpMap__TryFind(freshMap, id), (matchValue_1 != null) ? ((matchValue_1.tag === 15) ? ((v_3 = (matchValue_1.fields[0] | 0), v_3)) : id) : id), map((_arg_1, t_2) => subst(t_2), t_1.fields[1]), t_1.fields[2]]);
1338
+ }
953
1339
  case 5:
954
1340
  return new Type(/* TList */ 5, [subst(t_1.fields[0])]);
955
1341
  case 6:
956
1342
  return new Type(/* TTask */ 6, [subst(t_1.fields[0])]);
957
1343
  case 7:
958
- return new Type(/* TTuple */ 7, [map(subst, t_1.fields[0])]);
1344
+ return new Type(/* TTuple */ 7, [map_1(subst, t_1.fields[0])]);
959
1345
  case 8:
960
- return new Type(/* TRecord */ 8, [map_1((_arg_1, t1) => subst(t1), t_1.fields[0])]);
1346
+ return new Type(/* TRecord */ 8, [map((_arg_2, t1) => subst(t1), t_1.fields[0])]);
961
1347
  case 9:
962
1348
  return new Type(/* TMap */ 9, [subst(t_1.fields[0]), subst(t_1.fields[1])]);
963
1349
  case 10:
@@ -1238,7 +1624,7 @@ function resolveReferencedTypeName(knownNames, name, span) {
1238
1624
  }
1239
1625
  else if (name.indexOf(".") >= 0) {
1240
1626
  const shortName = last(split(name, ["."], undefined, 0));
1241
- const matches = toList_1(distinct(filter((candidate) => {
1627
+ const matches = toList_1(distinct(filter_1((candidate) => {
1242
1628
  if (candidate === shortName) {
1243
1629
  return true;
1244
1630
  }
@@ -1267,7 +1653,7 @@ function resolveReferencedTypeName(knownNames, name, span) {
1267
1653
  function annotationTypeFromRef(typeDefs, span, tref) {
1268
1654
  switch (tref.tag) {
1269
1655
  case 1:
1270
- return new Type(/* TTuple */ 7, [map((tref_1) => annotationTypeFromRef(typeDefs, span, tref_1), tref.fields[0])]);
1656
+ return new Type(/* TTuple */ 7, [map_1((tref_1) => annotationTypeFromRef(typeDefs, span, tref_1), tref.fields[0])]);
1271
1657
  case 2:
1272
1658
  return new Type(/* TFun */ 11, [annotationTypeFromRef(typeDefs, span, tref.fields[0]), annotationTypeFromRef(typeDefs, span, tref.fields[1])]);
1273
1659
  case 3:
@@ -1288,13 +1674,21 @@ function annotationTypeFromRef(typeDefs, span, tref) {
1288
1674
  return new Type(/* TMap */ 9, [(key.tag === 16) ? Type.TInt : key, annotationTypeFromRef(typeDefs, span, tref.fields[1])]);
1289
1675
  }
1290
1676
  case 5:
1291
- return resolveNamedRecordByShape(typeDefs, ofList(map((tupledArg) => [tupledArg[0], annotationTypeFromRef(typeDefs, span, tupledArg[1])], tref.fields[0]), {
1677
+ return resolveNamedRecordByShape(typeDefs, ofList(map_1((tupledArg) => [tupledArg[0], annotationTypeFromRef(typeDefs, span, tupledArg[1])], tref.fields[0]), {
1292
1678
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
1293
1679
  }), span);
1294
- case 6:
1295
- return new Type(/* TRecord */ 8, [ofList(map((tupledArg_1) => [tupledArg_1[0], annotationTypeFromRef(typeDefs, span, tupledArg_1[1])], tref.fields[0]), {
1680
+ case 6: {
1681
+ const fields_2 = ofList(map_1((tupledArg_1) => [tupledArg_1[0], annotationTypeFromRef(typeDefs, span, tupledArg_1[1])], tref.fields[0]), {
1296
1682
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
1297
- })]);
1683
+ });
1684
+ const matchValue = Types_freshVar();
1685
+ if (matchValue.tag === 15) {
1686
+ return new Type(/* TRecordShape */ 18, [matchValue.fields[0], fields_2, false]);
1687
+ }
1688
+ else {
1689
+ throw new Exception("Expected type variable");
1690
+ }
1691
+ }
1298
1692
  default:
1299
1693
  switch (tref.fields[0]) {
1300
1694
  case "unit":
@@ -1333,7 +1727,7 @@ function functionReturnType(t_mut) {
1333
1727
  function typeFromRef(decls, stack, tref) {
1334
1728
  switch (tref.tag) {
1335
1729
  case 1:
1336
- return new Type(/* TTuple */ 7, [map((tref_1) => typeFromRef(decls, stack, tref_1), tref.fields[0])]);
1730
+ return new Type(/* TTuple */ 7, [map_1((tref_1) => typeFromRef(decls, stack, tref_1), tref.fields[0])]);
1337
1731
  case 2:
1338
1732
  return new Type(/* TFun */ 11, [typeFromRef(decls, stack, tref.fields[0]), typeFromRef(decls, stack, tref.fields[1])]);
1339
1733
  case 3: {
@@ -1357,11 +1751,11 @@ function typeFromRef(decls, stack, tref) {
1357
1751
  return new Type(/* TMap */ 9, [(key.tag === 16) ? Type.TInt : key, typeFromRef(decls, stack, tref.fields[1])]);
1358
1752
  }
1359
1753
  case 5:
1360
- return new Type(/* TRecord */ 8, [ofList(map((tupledArg_1) => [tupledArg_1[0], typeFromRef(decls, stack, tupledArg_1[1])], tref.fields[0]), {
1754
+ return new Type(/* TRecord */ 8, [ofList(map_1((tupledArg_1) => [tupledArg_1[0], typeFromRef(decls, stack, tupledArg_1[1])], tref.fields[0]), {
1361
1755
  Compare: (x_1, y_2) => (comparePrimitives(x_1, y_2) | 0),
1362
1756
  })]);
1363
1757
  case 6:
1364
- return new Type(/* TRecord */ 8, [ofList(map((tupledArg_2) => [tupledArg_2[0], typeFromRef(decls, stack, tupledArg_2[1])], tref.fields[0]), {
1758
+ return new Type(/* TRecord */ 8, [ofList(map_1((tupledArg_2) => [tupledArg_2[0], typeFromRef(decls, stack, tupledArg_2[1])], tref.fields[0]), {
1365
1759
  Compare: (x_2, y_3) => (comparePrimitives(x_2, y_3) | 0),
1366
1760
  })]);
1367
1761
  default: {
@@ -1381,7 +1775,7 @@ function typeFromRef(decls, stack, tref) {
1381
1775
  return new Type(/* TNamed */ 12, [resolvedName]);
1382
1776
  }
1383
1777
  else {
1384
- return new Type(/* TRecord */ 8, [ofList(map((tupledArg) => [tupledArg[0], typeFromRef(decls, cons(resolvedName, stack), tupledArg[1])], def.Fields), {
1778
+ return new Type(/* TRecord */ 8, [ofList(map_1((tupledArg) => [tupledArg[0], typeFromRef(decls, cons(resolvedName, stack), tupledArg[1])], def.Fields), {
1385
1779
  Compare: (x, y_1) => (comparePrimitives(x, y_1) | 0),
1386
1780
  })]);
1387
1781
  }
@@ -1458,7 +1852,7 @@ function constrainMapKeyTypes(typeDefs, span, t) {
1458
1852
  while (true) {
1459
1853
  const current = current_mut;
1460
1854
  const matchValue = applyType(subst, current);
1461
- let matchResult, inner;
1855
+ let matchResult, inner, fields;
1462
1856
  switch (matchValue.tag) {
1463
1857
  case 9: {
1464
1858
  matchResult = 0;
@@ -1485,6 +1879,17 @@ function constrainMapKeyTypes(typeDefs, span, t) {
1485
1879
  }
1486
1880
  case 8: {
1487
1881
  matchResult = 3;
1882
+ fields = matchValue.fields[0];
1883
+ break;
1884
+ }
1885
+ case 18: {
1886
+ matchResult = 3;
1887
+ fields = matchValue.fields[1];
1888
+ break;
1889
+ }
1890
+ case 17: {
1891
+ matchResult = 3;
1892
+ fields = matchValue.fields[1];
1488
1893
  break;
1489
1894
  }
1490
1895
  case 11: {
@@ -1517,7 +1922,7 @@ function constrainMapKeyTypes(typeDefs, span, t) {
1517
1922
  break;
1518
1923
  }
1519
1924
  case 3: {
1520
- iterate_1(loop, values(matchValue.fields[0]));
1925
+ iterate_1(loop, values(fields));
1521
1926
  break;
1522
1927
  }
1523
1928
  case 4: {
@@ -1538,7 +1943,7 @@ function constrainMapKeyTypes(typeDefs, span, t) {
1538
1943
  }
1539
1944
 
1540
1945
  function inferPattern(telemetry, typeDefs, constructors, pat) {
1541
- let table_5;
1946
+ let matchValue, table_5;
1542
1947
  switch (pat.tag) {
1543
1948
  case 1: {
1544
1949
  const name = pat.fields[0];
@@ -1570,7 +1975,7 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1570
1975
  Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
1571
1976
  }), patternInput_1[1], new Type(/* TList */ 5, [t1]), pat.fields[2]);
1572
1977
  applySubstToCapturedLocals(telemetry, startIndex, s);
1573
- return [map_1((_arg, ty) => applyType(s, ty), fold_1((acc, k, v) => add(k, v, acc), patternInput[0], patternInput_1[0])), applyType(s, new Type(/* TList */ 5, [t1]))];
1978
+ return [map((_arg, ty) => applyType(s, ty), fold_1((acc, k, v) => add(k, v, acc), patternInput[0], patternInput_1[0])), applyType(s, new Type(/* TList */ 5, [t1]))];
1574
1979
  }
1575
1980
  case 5: {
1576
1981
  const patternInput_3 = fold((tupledArg, p) => {
@@ -1590,7 +1995,9 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1590
1995
  }), empty({
1591
1996
  Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
1592
1997
  })], pat.fields[0]);
1593
- return [patternInput_5[0], new Type(/* TRecord */ 8, [patternInput_5[1]])];
1998
+ return [patternInput_5[0], (matchValue = Types_freshVar(), (matchValue.tag === 15) ? (new Type(/* TRecordShape */ 18, [matchValue.fields[0], patternInput_5[1], false])) : (() => {
1999
+ throw new Exception("Expected type variable");
2000
+ })())];
1594
2001
  }
1595
2002
  case 7: {
1596
2003
  const tailPattern = pat.fields[1];
@@ -1616,7 +2023,7 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1616
2023
  ensureSupportedMapKeyType_1(applyType(sAcc, mapKeyType));
1617
2024
  const sValue = unify(typeDefs, applyType(sAcc, patternInput_7[1]), applyType(sAcc, valueType), span_1);
1618
2025
  sAcc = compose(sValue, sAcc);
1619
- const mergedClauseEnv = map_1((_arg_1, t_2) => applyType(sAcc, t_2), fold_1((acc_3, k_3, v_3) => add(k_3, v_3, acc_3), patternInput_7[0], patternInput_6[0]));
2026
+ const mergedClauseEnv = map((_arg_1, t_2) => applyType(sAcc, t_2), fold_1((acc_3, k_3, v_3) => add(k_3, v_3, acc_3), patternInput_7[0], patternInput_6[0]));
1620
2027
  envAcc_2 = fold_1((acc_4, k_4, v_4) => add(k_4, v_4, acc_4), envAcc_2, mergedClauseEnv);
1621
2028
  }
1622
2029
  }
@@ -1630,11 +2037,11 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1630
2037
  const expectedTailType = new Type(/* TMap */ 9, [applyType(sAcc, mapKeyType), applyType(sAcc, valueType)]);
1631
2038
  const sTail = unify(typeDefs, applyType(sAcc, patternInput_8[1]), expectedTailType, span_1);
1632
2039
  sAcc = compose(sTail, sAcc);
1633
- envAcc_2 = ((table_5 = map_1((_arg_2, t_3) => applyType(sAcc, t_3), patternInput_8[0]), fold_1((acc_5, k_5, v_5) => add(k_5, v_5, acc_5), envAcc_2, table_5)));
2040
+ envAcc_2 = ((table_5 = map((_arg_2, t_3) => applyType(sAcc, t_3), patternInput_8[0]), fold_1((acc_5, k_5, v_5) => add(k_5, v_5, acc_5), envAcc_2, table_5)));
1634
2041
  }
1635
2042
  ensureSupportedMapKeyType_1(applyType(sAcc, mapKeyType));
1636
2043
  applySubstToCapturedLocals(telemetry, startIndex_1, sAcc);
1637
- return [map_1((_arg_3, t_4) => applyType(sAcc, t_4), envAcc_2), new Type(/* TMap */ 9, [applyType(sAcc, mapKeyType), applyType(sAcc, valueType)])];
2044
+ return [map((_arg_3, t_4) => applyType(sAcc, t_4), envAcc_2), new Type(/* TMap */ 9, [applyType(sAcc, mapKeyType), applyType(sAcc, valueType)])];
1638
2045
  }
1639
2046
  case 8: {
1640
2047
  const patternInput_9 = inferPattern(telemetry, typeDefs, constructors, pat.fields[0]);
@@ -1652,23 +2059,23 @@ function inferPattern(telemetry, typeDefs, constructors, pat) {
1652
2059
  const payload = pat.fields[2];
1653
2060
  const caseName = pat.fields[1];
1654
2061
  const constructorName = (qualifier == null) ? caseName : concat(qualifier, ".", caseName);
1655
- const matchValue = FSharpMap__TryFind(constructors, constructorName);
1656
- if (matchValue != null) {
1657
- const sigInfo = matchValue;
2062
+ const matchValue_1 = FSharpMap__TryFind(constructors, constructorName);
2063
+ if (matchValue_1 != null) {
2064
+ const sigInfo = matchValue_1;
1658
2065
  const unionType = new Type(/* TNamed */ 12, [sigInfo.UnionName]);
1659
- const matchValue_1 = sigInfo.Payload;
1660
- if (matchValue_1 != null) {
2066
+ const matchValue_2 = sigInfo.Payload;
2067
+ if (matchValue_2 != null) {
1661
2068
  if (payload == null) {
1662
2069
  throw new TypeException(new TypeError$(toText(printf("Union case \'%s\' requires a payload"))(constructorName), span_2));
1663
2070
  }
1664
2071
  else {
1665
- const expectedPayload = matchValue_1;
2072
+ const expectedPayload = matchValue_2;
1666
2073
  const payloadPattern = payload;
1667
2074
  const startIndex_2 = currentTelemetryCaptureCount(telemetry) | 0;
1668
2075
  const patternInput_10 = inferPattern(telemetry, typeDefs, constructors, payloadPattern);
1669
2076
  const s_1 = unify(typeDefs, patternInput_10[1], expectedPayload, span_2);
1670
2077
  applySubstToCapturedLocals(telemetry, startIndex_2, s_1);
1671
- return [map_1((_arg_4, t_6) => applyType(s_1, t_6), patternInput_10[0]), unionType];
2078
+ return [map((_arg_4, t_6) => applyType(s_1, t_6), patternInput_10[0]), unionType];
1672
2079
  }
1673
2080
  }
1674
2081
  else if (payload != null) {
@@ -1714,45 +2121,90 @@ function validateMapKeyTypes(typeDefs, span, t) {
1714
2121
  loop:
1715
2122
  while (true) {
1716
2123
  const t_1 = t_1_mut;
2124
+ let matchResult, fields;
1717
2125
  switch (t_1.tag) {
1718
2126
  case 9: {
2127
+ matchResult = 0;
2128
+ break;
2129
+ }
2130
+ case 5: {
2131
+ matchResult = 1;
2132
+ break;
2133
+ }
2134
+ case 6: {
2135
+ matchResult = 2;
2136
+ break;
2137
+ }
2138
+ case 7: {
2139
+ matchResult = 3;
2140
+ break;
2141
+ }
2142
+ case 8: {
2143
+ matchResult = 4;
2144
+ fields = t_1.fields[0];
2145
+ break;
2146
+ }
2147
+ case 18: {
2148
+ matchResult = 4;
2149
+ fields = t_1.fields[1];
2150
+ break;
2151
+ }
2152
+ case 17: {
2153
+ matchResult = 4;
2154
+ fields = t_1.fields[1];
2155
+ break;
2156
+ }
2157
+ case 10: {
2158
+ matchResult = 5;
2159
+ break;
2160
+ }
2161
+ case 11: {
2162
+ matchResult = 6;
2163
+ break;
2164
+ }
2165
+ default:
2166
+ matchResult = 7;
2167
+ }
2168
+ switch (matchResult) {
2169
+ case 0: {
1719
2170
  const keyType = t_1.fields[0];
1720
2171
  loop(keyType);
1721
2172
  loop(t_1.fields[1]);
1722
2173
  ensureSupportedMapKeyType(typeDefs, span, keyType);
1723
2174
  break;
1724
2175
  }
1725
- case 5: {
2176
+ case 1: {
1726
2177
  t_1_mut = t_1.fields[0];
1727
2178
  continue loop;
1728
2179
  break;
1729
2180
  }
1730
- case 6: {
2181
+ case 2: {
1731
2182
  t_1_mut = t_1.fields[0];
1732
2183
  continue loop;
1733
2184
  break;
1734
2185
  }
1735
- case 7: {
2186
+ case 3: {
1736
2187
  iterate(loop, t_1.fields[0]);
1737
2188
  break;
1738
2189
  }
1739
- case 8: {
1740
- iterate_1(loop, values(t_1.fields[0]));
2190
+ case 4: {
2191
+ iterate_1(loop, values(fields));
1741
2192
  break;
1742
2193
  }
1743
- case 10: {
2194
+ case 5: {
1744
2195
  t_1_mut = t_1.fields[0];
1745
2196
  continue loop;
1746
2197
  break;
1747
2198
  }
1748
- case 11: {
2199
+ case 6: {
1749
2200
  loop(t_1.fields[0]);
1750
2201
  t_1_mut = t_1.fields[1];
1751
2202
  continue loop;
1752
2203
  break;
1753
2204
  }
1754
- default:
1755
- undefined;
2205
+ case 7: {
2206
+ break;
2207
+ }
1756
2208
  }
1757
2209
  break;
1758
2210
  }
@@ -1929,14 +2381,14 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
1929
2381
  const sValue_2 = compose(unify(typeDefs, applyType(s1_8, patternInput_15[1]), patternInput_16[1], expr.fields[3]), s1_8);
1930
2382
  applySubstToCapturedLocals(telemetry, startIndex, sValue_2);
1931
2383
  const env1_2 = applyEnv(sValue_2, env);
1932
- const envPatTyped = map_1((_arg, ty) => applyType(sValue_2, ty), patternInput_16[0]);
2384
+ const envPatTyped = map((_arg, ty) => applyType(sValue_2, ty), patternInput_16[0]);
1933
2385
  const env2_4 = fold_1((state, name_5, bindingType) => add(name_5, Types_generalize(env1_2, bindingType), state), env1_2, envPatTyped);
1934
- const patternInput_17 = withLocalBindings(telemetry, map((tuple) => tuple[0], toList(envPatTyped)), () => inferExpr(telemetry, typeDefs, constructors, env2_4, expr.fields[2]));
2386
+ const patternInput_17 = withLocalBindings(telemetry, map_1((tuple) => tuple[0], toList(envPatTyped)), () => inferExpr(telemetry, typeDefs, constructors, env2_4, expr.fields[2]));
1935
2387
  const tBody_3 = patternInput_17[1];
1936
2388
  return [compose(patternInput_17[0], sValue_2), tBody_3, asTyped(expr, tBody_3)];
1937
2389
  }
1938
2390
  case 12: {
1939
- const foldedBindings = map((tupledArg) => {
2391
+ const foldedBindings = map_1((tupledArg) => {
1940
2392
  const args = tupledArg[1];
1941
2393
  const bindingSpan = tupledArg[4];
1942
2394
  if (isEmpty_1(args)) {
@@ -1944,12 +2396,12 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
1944
2396
  }
1945
2397
  return [tupledArg[0], tupledArg[2], foldBack((arg_4, acc) => (new Expr(/* ELambda */ 4, [arg_4, acc, bindingSpan])), args, tupledArg[3]), bindingSpan];
1946
2398
  }, expr.fields[0]);
1947
- const freshByName = ofList(map((tupledArg_1) => [tupledArg_1[0], Types_freshVar()], foldedBindings), {
2399
+ const freshByName = ofList(map_1((tupledArg_1) => [tupledArg_1[0], Types_freshVar()], foldedBindings), {
1948
2400
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
1949
2401
  });
1950
2402
  const envRec_1 = fold_1((acc_1, name_8, tv_4) => add(name_8, new Scheme(empty_2(), tv_4), acc_1), env, freshByName);
1951
2403
  let sRec = emptySubst;
1952
- const recursiveNames = map((tuple_1) => tuple_1[0], toList(freshByName));
2404
+ const recursiveNames = map_1((tuple_1) => tuple_1[0], toList(freshByName));
1953
2405
  withLocalBindings(telemetry, recursiveNames, () => {
1954
2406
  const enumerator_1 = getEnumerator(foldedBindings);
1955
2407
  try {
@@ -1984,7 +2436,7 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
1984
2436
  disposeSafe(enumerator_2);
1985
2437
  }
1986
2438
  const envGeneralize = applyEnv(sRec, env);
1987
- const envBody_1 = fold((acc_2, tupledArg_3) => add(tupledArg_3[0], tupledArg_3[1], acc_2), envGeneralize, map((tupledArg_2) => {
2439
+ const envBody_1 = fold((acc_2, tupledArg_3) => add(tupledArg_3[0], tupledArg_3[1], acc_2), envGeneralize, map_1((tupledArg_2) => {
1988
2440
  const name_11 = tupledArg_2[0];
1989
2441
  return [name_11, Types_generalize(envGeneralize, applyType(sRec, FSharpMap__get_Item(freshByName, name_11)))];
1990
2442
  }, foldedBindings));
@@ -1994,7 +2446,6 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
1994
2446
  }
1995
2447
  case 9: {
1996
2448
  const patternInput_20 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
1997
- const tScrut = patternInput_20[1];
1998
2449
  let sAcc_1 = patternInput_20[0];
1999
2450
  let resultTypeOpt = undefined;
2000
2451
  const enumerator_3 = getEnumerator(expr.fields[1]);
@@ -2002,101 +2453,13 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2002
2453
  while (enumerator_3["System.Collections.IEnumerator.MoveNext"]()) {
2003
2454
  let tPrev, sEq;
2004
2455
  const forLoopVar_2 = enumerator_3["System.Collections.Generic.IEnumerator`1.get_Current"]();
2005
- const pat_1 = forLoopVar_2[0];
2006
2456
  const guard = forLoopVar_2[1];
2007
2457
  const caseSpan = forLoopVar_2[3];
2008
- const patternInput_21 = inferPattern(telemetry, typeDefs, constructors, pat_1);
2009
- const tPat_1 = patternInput_21[1];
2458
+ const patternInput_21 = inferPattern(telemetry, typeDefs, constructors, forLoopVar_2[0]);
2010
2459
  const envPat_1 = patternInput_21[0];
2011
- let sPat;
2012
- const matchValue_2 = applyType(sAcc_1, tScrut);
2013
- let matchResult, patFields, scrutFields, patFields_1, typeName;
2014
- if (pat_1.tag === 6) {
2015
- switch (matchValue_2.tag) {
2016
- case 8: {
2017
- if (tPat_1.tag === 8) {
2018
- matchResult = 0;
2019
- patFields = tPat_1.fields[0];
2020
- scrutFields = matchValue_2.fields[0];
2021
- }
2022
- else {
2023
- matchResult = 2;
2024
- }
2025
- break;
2026
- }
2027
- case 12: {
2028
- if (tPat_1.tag === 8) {
2029
- matchResult = 1;
2030
- patFields_1 = tPat_1.fields[0];
2031
- typeName = matchValue_2.fields[0];
2032
- }
2033
- else {
2034
- matchResult = 2;
2035
- }
2036
- break;
2037
- }
2038
- default:
2039
- matchResult = 2;
2040
- }
2041
- }
2042
- else {
2043
- matchResult = 3;
2044
- }
2045
- switch (matchResult) {
2046
- case 0: {
2047
- sPat = fold_1((sLocal, field, patTy) => {
2048
- const matchValue_4 = FSharpMap__TryFind(scrutFields, field);
2049
- if (matchValue_4 == null) {
2050
- throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(field), caseSpan));
2051
- }
2052
- else {
2053
- return compose(unify(typeDefs, applyType(sLocal, matchValue_4), applyType(sLocal, patTy), caseSpan), sLocal);
2054
- }
2055
- }, emptySubst, patFields);
2056
- break;
2057
- }
2058
- case 1: {
2059
- const matchValue_5 = FSharpMap__TryFind(typeDefs, typeName);
2060
- let matchResult_1, scrutFields_1;
2061
- if (matchValue_5 != null) {
2062
- if (matchValue_5.tag === 8) {
2063
- matchResult_1 = 0;
2064
- scrutFields_1 = matchValue_5.fields[0];
2065
- }
2066
- else {
2067
- matchResult_1 = 1;
2068
- }
2069
- }
2070
- else {
2071
- matchResult_1 = 1;
2072
- }
2073
- switch (matchResult_1) {
2074
- case 0: {
2075
- sPat = fold_1((sLocal_1, field_1, patTy_1) => {
2076
- const matchValue_6 = FSharpMap__TryFind(scrutFields_1, field_1);
2077
- if (matchValue_6 == null) {
2078
- throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(field_1), caseSpan));
2079
- }
2080
- else {
2081
- return compose(unify(typeDefs, applyType(sLocal_1, matchValue_6), applyType(sLocal_1, patTy_1), caseSpan), sLocal_1);
2082
- }
2083
- }, emptySubst, patFields_1);
2084
- break;
2085
- }
2086
- default:
2087
- throw new TypeException(new TypeError$("Record pattern requires a concrete record scrutinee type", caseSpan));
2088
- }
2089
- break;
2090
- }
2091
- case 2: {
2092
- throw new TypeException(new TypeError$("Record pattern requires a concrete record scrutinee type", caseSpan));
2093
- break;
2094
- }
2095
- default:
2096
- sPat = unify(typeDefs, applyType(sAcc_1, tScrut), tPat_1, caseSpan);
2097
- }
2460
+ const sPat = unify(typeDefs, applyType(sAcc_1, patternInput_20[1]), patternInput_21[1], caseSpan);
2098
2461
  const envCase$0027 = fold_1((acc_3, k, v) => add(k, new Scheme(empty_2(), applyType(sPat, v)), acc_3), applyEnv(compose(sPat, sAcc_1), env), envPat_1);
2099
- const patternInput_23 = withLocalBindings(telemetry, map((tuple_2) => tuple_2[0], toList(envPat_1)), () => {
2462
+ const patternInput_23 = withLocalBindings(telemetry, map_1((tuple_2) => tuple_2[0], toList(envPat_1)), () => {
2100
2463
  let envBodyCase = envCase$0027;
2101
2464
  if (guard == null) {
2102
2465
  }
@@ -2257,32 +2620,74 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2257
2620
  case 19: {
2258
2621
  const span_16 = expr.fields[2];
2259
2622
  const patternInput_33 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2260
- const sBase = patternInput_33[0];
2623
+ const tBase = patternInput_33[1];
2624
+ const sInitial = patternInput_33[0];
2625
+ let sBase;
2626
+ const matchValue_2 = applyType(sInitial, tBase);
2627
+ if (matchValue_2.tag === 18) {
2628
+ const id = matchValue_2.fields[0] | 0;
2629
+ sBase = compose(ofList(singleton([id, new Type(/* TRecordShape */ 18, [id, matchValue_2.fields[1], true])]), {
2630
+ Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
2631
+ }), sInitial);
2632
+ }
2633
+ else {
2634
+ sBase = sInitial;
2635
+ }
2261
2636
  let baseFields;
2262
- const matchValue_7 = applyType(sBase, patternInput_33[1]);
2263
- switch (matchValue_7.tag) {
2637
+ const matchValue_3 = applyType(sBase, tBase);
2638
+ let matchResult, fields_3;
2639
+ switch (matchValue_3.tag) {
2264
2640
  case 8: {
2265
- baseFields = matchValue_7.fields[0];
2641
+ matchResult = 0;
2642
+ fields_3 = matchValue_3.fields[0];
2643
+ break;
2644
+ }
2645
+ case 18: {
2646
+ matchResult = 0;
2647
+ fields_3 = matchValue_3.fields[1];
2266
2648
  break;
2267
2649
  }
2268
2650
  case 12: {
2269
- const matchValue_8 = FSharpMap__TryFind(typeDefs, matchValue_7.fields[0]);
2270
- let matchResult_2, fields_3;
2271
- if (matchValue_8 != null) {
2272
- if (matchValue_8.tag === 8) {
2273
- matchResult_2 = 0;
2274
- fields_3 = matchValue_8.fields[0];
2275
- }
2276
- else {
2277
- matchResult_2 = 1;
2651
+ matchResult = 1;
2652
+ break;
2653
+ }
2654
+ default:
2655
+ matchResult = 2;
2656
+ }
2657
+ switch (matchResult) {
2658
+ case 0: {
2659
+ baseFields = fields_3;
2660
+ break;
2661
+ }
2662
+ case 1: {
2663
+ const name_15 = matchValue_3.fields[0];
2664
+ const matchValue_4 = FSharpMap__TryFind(typeDefs, name_15);
2665
+ let matchResult_1, fields_4;
2666
+ if (matchValue_4 != null) {
2667
+ switch (matchValue_4.tag) {
2668
+ case 8: {
2669
+ matchResult_1 = 0;
2670
+ fields_4 = matchValue_4.fields[0];
2671
+ break;
2672
+ }
2673
+ case 17: {
2674
+ matchResult_1 = 1;
2675
+ break;
2676
+ }
2677
+ default:
2678
+ matchResult_1 = 2;
2278
2679
  }
2279
2680
  }
2280
2681
  else {
2281
- matchResult_2 = 1;
2682
+ matchResult_1 = 2;
2282
2683
  }
2283
- switch (matchResult_2) {
2684
+ switch (matchResult_1) {
2284
2685
  case 0: {
2285
- baseFields = fields_3;
2686
+ baseFields = fields_4;
2687
+ break;
2688
+ }
2689
+ case 1: {
2690
+ throw new TypeException(new TypeError$(concat("Host-managed type \'", name_15, "\' cannot be updated"), span_16));
2286
2691
  break;
2287
2692
  }
2288
2693
  default:
@@ -2301,55 +2706,97 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2301
2706
  const valueExpr_4 = forLoopVar_5[1];
2302
2707
  const name_16 = forLoopVar_5[0];
2303
2708
  let expectedFieldType;
2304
- const matchValue_9 = FSharpMap__TryFind(baseFields, name_16);
2305
- if (matchValue_9 == null) {
2709
+ const matchValue_5 = FSharpMap__TryFind(baseFields, name_16);
2710
+ if (matchValue_5 == null) {
2306
2711
  throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(name_16), Ast_spanOfExpr(valueExpr_4)));
2307
2712
  }
2308
2713
  else {
2309
- expectedFieldType = matchValue_9;
2714
+ expectedFieldType = matchValue_5;
2310
2715
  }
2311
2716
  const patternInput_34 = inferExpr(telemetry, typeDefs, constructors, applyEnv(sAcc_7, env), valueExpr_4);
2312
- const sField_2 = patternInput_34[0];
2313
- const sEq_1 = unify(typeDefs, applyType(sField_2, applyType(sAcc_7, expectedFieldType)), patternInput_34[1], Ast_spanOfExpr(valueExpr_4));
2314
- sAcc_7 = compose(sEq_1, compose(sField_2, sAcc_7));
2717
+ const sField = patternInput_34[0];
2718
+ const sEq_1 = unify(typeDefs, applyType(sField, applyType(sAcc_7, expectedFieldType)), patternInput_34[1], Ast_spanOfExpr(valueExpr_4));
2719
+ sAcc_7 = compose(sEq_1, compose(sField, sAcc_7));
2315
2720
  }
2316
2721
  }
2317
2722
  finally {
2318
2723
  disposeSafe(enumerator_9);
2319
2724
  }
2320
- const tRes_10 = new Type(/* TRecord */ 8, [map_1((_arg_7, t_5) => applyType(sAcc_7, t_5), baseFields)]);
2725
+ const tRes_10 = new Type(/* TRecord */ 8, [map((_arg_7, t_5) => applyType(sAcc_7, t_5), baseFields)]);
2321
2726
  return [sAcc_7, tRes_10, asTyped(expr, tRes_10)];
2322
2727
  }
2323
2728
  case 20: {
2324
2729
  const span_17 = expr.fields[2];
2325
2730
  const patternInput_35 = inferExpr(telemetry, typeDefs, constructors, env, expr.fields[0]);
2326
- const sBase_1 = patternInput_35[0];
2731
+ const tBase_1 = patternInput_35[1];
2732
+ const sInitial_1 = patternInput_35[0];
2733
+ let sBase_1;
2734
+ const matchValue_6 = applyType(sInitial_1, tBase_1);
2735
+ if (matchValue_6.tag === 18) {
2736
+ const id_1 = matchValue_6.fields[0] | 0;
2737
+ sBase_1 = compose(ofList(singleton([id_1, new Type(/* TRecordShape */ 18, [id_1, matchValue_6.fields[1], true])]), {
2738
+ Compare: (x_5, y_5) => (comparePrimitives(x_5, y_5) | 0),
2739
+ }), sInitial_1);
2740
+ }
2741
+ else {
2742
+ sBase_1 = sInitial_1;
2743
+ }
2327
2744
  let sAcc_8 = sBase_1;
2328
2745
  let resultFields_1;
2329
- const matchValue_10 = applyType(sBase_1, patternInput_35[1]);
2330
- switch (matchValue_10.tag) {
2746
+ const matchValue_7 = applyType(sBase_1, tBase_1);
2747
+ let matchResult_2, fields_6;
2748
+ switch (matchValue_7.tag) {
2331
2749
  case 8: {
2332
- resultFields_1 = matchValue_10.fields[0];
2750
+ matchResult_2 = 0;
2751
+ fields_6 = matchValue_7.fields[0];
2752
+ break;
2753
+ }
2754
+ case 18: {
2755
+ matchResult_2 = 0;
2756
+ fields_6 = matchValue_7.fields[1];
2333
2757
  break;
2334
2758
  }
2335
2759
  case 12: {
2336
- const matchValue_11 = FSharpMap__TryFind(typeDefs, matchValue_10.fields[0]);
2337
- let matchResult_3, fields_5;
2338
- if (matchValue_11 != null) {
2339
- if (matchValue_11.tag === 8) {
2340
- matchResult_3 = 0;
2341
- fields_5 = matchValue_11.fields[0];
2342
- }
2343
- else {
2344
- matchResult_3 = 1;
2760
+ matchResult_2 = 1;
2761
+ break;
2762
+ }
2763
+ default:
2764
+ matchResult_2 = 2;
2765
+ }
2766
+ switch (matchResult_2) {
2767
+ case 0: {
2768
+ resultFields_1 = fields_6;
2769
+ break;
2770
+ }
2771
+ case 1: {
2772
+ const name_17 = matchValue_7.fields[0];
2773
+ const matchValue_8 = FSharpMap__TryFind(typeDefs, name_17);
2774
+ let matchResult_3, fields_7;
2775
+ if (matchValue_8 != null) {
2776
+ switch (matchValue_8.tag) {
2777
+ case 8: {
2778
+ matchResult_3 = 0;
2779
+ fields_7 = matchValue_8.fields[0];
2780
+ break;
2781
+ }
2782
+ case 17: {
2783
+ matchResult_3 = 1;
2784
+ break;
2785
+ }
2786
+ default:
2787
+ matchResult_3 = 2;
2345
2788
  }
2346
2789
  }
2347
2790
  else {
2348
- matchResult_3 = 1;
2791
+ matchResult_3 = 2;
2349
2792
  }
2350
2793
  switch (matchResult_3) {
2351
2794
  case 0: {
2352
- resultFields_1 = fields_5;
2795
+ resultFields_1 = fields_7;
2796
+ break;
2797
+ }
2798
+ case 1: {
2799
+ throw new TypeException(new TypeError$(concat("Host-managed type \'", name_17, "\' cannot be updated"), span_17));
2353
2800
  break;
2354
2801
  }
2355
2802
  default:
@@ -2363,22 +2810,22 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2363
2810
  const enumerator_10 = getEnumerator(expr.fields[1]);
2364
2811
  try {
2365
2812
  while (enumerator_10["System.Collections.IEnumerator.MoveNext"]()) {
2366
- let matchValue_12, existingFieldType, table_17;
2813
+ let matchValue_9, existingFieldType, table_15;
2367
2814
  const forLoopVar_6 = enumerator_10["System.Collections.Generic.IEnumerator`1.get_Current"]();
2368
2815
  const valueExpr_5 = forLoopVar_6[1];
2369
2816
  const name_18 = forLoopVar_6[0];
2370
2817
  const patternInput_36 = inferExpr(telemetry, typeDefs, constructors, applyEnv(sAcc_8, env), valueExpr_5);
2371
- const sField_3 = patternInput_36[0];
2372
- const tFieldApplied = applyType(sField_3, patternInput_36[1]);
2373
- const sEq_2 = unify(typeDefs, (matchValue_12 = FSharpMap__TryFind(resultFields_1, name_18), (matchValue_12 == null) ? tFieldApplied : ((existingFieldType = matchValue_12, applyType(sField_3, applyType(sAcc_8, existingFieldType))))), tFieldApplied, Ast_spanOfExpr(valueExpr_5));
2374
- sAcc_8 = compose(sEq_2, compose(sField_3, sAcc_8));
2375
- resultFields_1 = ((table_17 = resultFields_1, add(name_18, applyType(sAcc_8, tFieldApplied), table_17)));
2818
+ const sField_1 = patternInput_36[0];
2819
+ const tFieldApplied = applyType(sField_1, patternInput_36[1]);
2820
+ const sEq_2 = unify(typeDefs, (matchValue_9 = FSharpMap__TryFind(resultFields_1, name_18), (matchValue_9 == null) ? tFieldApplied : ((existingFieldType = matchValue_9, applyType(sField_1, applyType(sAcc_8, existingFieldType))))), tFieldApplied, Ast_spanOfExpr(valueExpr_5));
2821
+ sAcc_8 = compose(sEq_2, compose(sField_1, sAcc_8));
2822
+ resultFields_1 = ((table_15 = resultFields_1, add(name_18, applyType(sAcc_8, tFieldApplied), table_15)));
2376
2823
  }
2377
2824
  }
2378
2825
  finally {
2379
2826
  disposeSafe(enumerator_10);
2380
2827
  }
2381
- const tRes_11 = new Type(/* TRecord */ 8, [map_1((_arg_8, t_6) => applyType(sAcc_8, t_6), resultFields_1)]);
2828
+ const tRes_11 = new Type(/* TRecord */ 8, [map((_arg_8, t_6) => applyType(sAcc_8, t_6), resultFields_1)]);
2382
2829
  return [sAcc_8, tRes_11, asTyped(expr, tRes_11)];
2383
2830
  }
2384
2831
  case 21: {
@@ -2386,89 +2833,140 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2386
2833
  const span_18 = expr.fields[2];
2387
2834
  const fieldName = expr.fields[1];
2388
2835
  const inferRecordField = (s1_16, tTarget) => {
2389
- const matchValue_13 = applyType(s1_16, tTarget);
2390
- switch (matchValue_13.tag) {
2836
+ let matchValue_15;
2837
+ const matchValue_10 = applyType(s1_16, tTarget);
2838
+ let matchResult_4, fields_9;
2839
+ switch (matchValue_10.tag) {
2840
+ case 18: {
2841
+ matchResult_4 = 0;
2842
+ break;
2843
+ }
2391
2844
  case 8: {
2392
- const matchValue_14 = FSharpMap__TryFind(matchValue_13.fields[0], fieldName);
2393
- if (matchValue_14 == null) {
2845
+ matchResult_4 = 1;
2846
+ fields_9 = matchValue_10.fields[0];
2847
+ break;
2848
+ }
2849
+ case 17: {
2850
+ matchResult_4 = 1;
2851
+ fields_9 = matchValue_10.fields[1];
2852
+ break;
2853
+ }
2854
+ case 12: {
2855
+ matchResult_4 = 2;
2856
+ break;
2857
+ }
2858
+ case 15: {
2859
+ matchResult_4 = 3;
2860
+ break;
2861
+ }
2862
+ default:
2863
+ matchResult_4 = 4;
2864
+ }
2865
+ switch (matchResult_4) {
2866
+ case 0: {
2867
+ const id_2 = matchValue_10.fields[0] | 0;
2868
+ const fields_8 = matchValue_10.fields[1];
2869
+ const matchValue_11 = FSharpMap__TryFind(fields_8, fieldName);
2870
+ if (matchValue_11 == null) {
2871
+ const tField_3 = Types_freshVar();
2872
+ return [compose(ofList(singleton([id_2, new Type(/* TRecordShape */ 18, [id_2, FSharpMap__Add(fields_8, fieldName, tField_3), matchValue_10.fields[2]])]), {
2873
+ Compare: (x_6, y_6) => (comparePrimitives(x_6, y_6) | 0),
2874
+ }), s1_16), tField_3];
2875
+ }
2876
+ else {
2877
+ return [s1_16, matchValue_11];
2878
+ }
2879
+ }
2880
+ case 1: {
2881
+ const matchValue_12 = FSharpMap__TryFind(fields_9, fieldName);
2882
+ if (matchValue_12 == null) {
2394
2883
  throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(fieldName), span_18));
2395
2884
  }
2396
2885
  else {
2397
- return [s1_16, matchValue_14];
2886
+ return [s1_16, matchValue_12];
2398
2887
  }
2399
2888
  }
2400
- case 12: {
2401
- const matchValue_15 = FSharpMap__TryFind(typeDefs, matchValue_13.fields[0]);
2402
- let matchResult_4, fields_7;
2403
- if (matchValue_15 != null) {
2404
- if (matchValue_15.tag === 8) {
2405
- matchResult_4 = 0;
2406
- fields_7 = matchValue_15.fields[0];
2407
- }
2408
- else {
2409
- matchResult_4 = 1;
2889
+ case 2: {
2890
+ const matchValue_13 = FSharpMap__TryFind(typeDefs, matchValue_10.fields[0]);
2891
+ let matchResult_5, fields_10;
2892
+ if (matchValue_13 != null) {
2893
+ switch (matchValue_13.tag) {
2894
+ case 8: {
2895
+ matchResult_5 = 0;
2896
+ fields_10 = matchValue_13.fields[0];
2897
+ break;
2898
+ }
2899
+ case 17: {
2900
+ matchResult_5 = 0;
2901
+ fields_10 = matchValue_13.fields[1];
2902
+ break;
2903
+ }
2904
+ default:
2905
+ matchResult_5 = 1;
2410
2906
  }
2411
2907
  }
2412
2908
  else {
2413
- matchResult_4 = 1;
2909
+ matchResult_5 = 1;
2414
2910
  }
2415
- switch (matchResult_4) {
2911
+ switch (matchResult_5) {
2416
2912
  case 0: {
2417
- const matchValue_16 = FSharpMap__TryFind(fields_7, fieldName);
2418
- if (matchValue_16 == null) {
2913
+ const matchValue_14 = FSharpMap__TryFind(fields_10, fieldName);
2914
+ if (matchValue_14 == null) {
2419
2915
  throw new TypeException(new TypeError$(toText(printf("Record field \'%s\' not found"))(fieldName), span_18));
2420
2916
  }
2421
2917
  else {
2422
- return [s1_16, matchValue_16];
2918
+ return [s1_16, matchValue_14];
2423
2919
  }
2424
2920
  }
2425
2921
  default:
2426
2922
  throw new TypeException(new TypeError$("Field access requires a record value", span_18));
2427
2923
  }
2428
2924
  }
2429
- case 15: {
2430
- const tField_4 = Types_freshVar();
2431
- const s_11 = compose(unify(typeDefs, matchValue_13, new Type(/* TRecord */ 8, [ofList(singleton([fieldName, tField_4]), {
2432
- Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
2433
- })]), span_18), s1_16);
2434
- return [s_11, applyType(s_11, tField_4)];
2925
+ case 3: {
2926
+ const tField_6 = Types_freshVar();
2927
+ const s_12 = compose(unify(typeDefs, matchValue_10, (matchValue_15 = Types_freshVar(), (matchValue_15.tag === 15) ? (new Type(/* TRecordShape */ 18, [matchValue_15.fields[0], ofList(singleton([fieldName, tField_6]), {
2928
+ Compare: (x_7, y_7) => (comparePrimitives(x_7, y_7) | 0),
2929
+ }), false])) : (() => {
2930
+ throw new Exception("Expected type variable");
2931
+ })()), span_18), s1_16);
2932
+ return [s_12, applyType(s_12, tField_6)];
2435
2933
  }
2436
2934
  default:
2437
2935
  throw new TypeException(new TypeError$("Field access requires a record value", span_18));
2438
2936
  }
2439
2937
  };
2440
- let matchResult_5, moduleName_1;
2938
+ let matchResult_6, moduleName_1;
2441
2939
  if (target.tag === 2) {
2442
2940
  if (!FSharpMap__ContainsKey(env, target.fields[0])) {
2443
- matchResult_5 = 0;
2941
+ matchResult_6 = 0;
2444
2942
  moduleName_1 = target.fields[0];
2445
2943
  }
2446
2944
  else {
2447
- matchResult_5 = 1;
2945
+ matchResult_6 = 1;
2448
2946
  }
2449
2947
  }
2450
2948
  else {
2451
- matchResult_5 = 1;
2949
+ matchResult_6 = 1;
2452
2950
  }
2453
- switch (matchResult_5) {
2951
+ switch (matchResult_6) {
2454
2952
  case 0: {
2455
- const matchValue_17 = FSharpMap__TryFind(env, concat(moduleName_1, ".", fieldName));
2456
- if (matchValue_17 == null) {
2953
+ const matchValue_16 = FSharpMap__TryFind(env, concat(moduleName_1, ".", fieldName));
2954
+ if (matchValue_16 == null) {
2457
2955
  const patternInput_37 = inferExpr(telemetry, typeDefs, constructors, env, target);
2458
2956
  const patternInput_38 = inferRecordField(patternInput_37[0], patternInput_37[1]);
2459
- const tField_5 = patternInput_38[1];
2460
- return [patternInput_38[0], tField_5, asTyped(expr, tField_5)];
2957
+ const tField_7 = patternInput_38[1];
2958
+ return [patternInput_38[0], tField_7, asTyped(expr, tField_7)];
2461
2959
  }
2462
2960
  else {
2463
- const t_7 = instantiate(matchValue_17);
2961
+ const t_7 = instantiate(matchValue_16);
2464
2962
  return [emptySubst, t_7, asTyped(expr, t_7)];
2465
2963
  }
2466
2964
  }
2467
2965
  default: {
2468
2966
  const patternInput_39 = inferExpr(telemetry, typeDefs, constructors, env, target);
2469
2967
  const patternInput_40 = inferRecordField(patternInput_39[0], patternInput_39[1]);
2470
- const tField_6 = patternInput_40[1];
2471
- return [patternInput_40[0], tField_6, asTyped(expr, tField_6)];
2968
+ const tField_8 = patternInput_40[1];
2969
+ return [patternInput_40[0], tField_8, asTyped(expr, tField_8)];
2472
2970
  }
2473
2971
  }
2474
2972
  }
@@ -2480,15 +2978,15 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2480
2978
  const s2_10 = patternInput_42[0];
2481
2979
  const targetType = applyType(s2_10, patternInput_41[1]);
2482
2980
  const keyType_1 = applyType(s2_10, patternInput_42[1]);
2483
- let matchResult_6, itemType_1, mapKeyType, valueType_1;
2981
+ let matchResult_7, itemType_1, mapKeyType, valueType_1;
2484
2982
  switch (targetType.tag) {
2485
2983
  case 5: {
2486
- matchResult_6 = 0;
2984
+ matchResult_7 = 0;
2487
2985
  itemType_1 = targetType.fields[0];
2488
2986
  break;
2489
2987
  }
2490
2988
  case 9: {
2491
- matchResult_6 = 1;
2989
+ matchResult_7 = 1;
2492
2990
  mapKeyType = targetType.fields[0];
2493
2991
  valueType_1 = targetType.fields[1];
2494
2992
  break;
@@ -2496,51 +2994,51 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2496
2994
  case 15: {
2497
2995
  switch (keyType_1.tag) {
2498
2996
  case 1: {
2499
- matchResult_6 = 2;
2997
+ matchResult_7 = 2;
2500
2998
  break;
2501
2999
  }
2502
3000
  case 4:
2503
3001
  case 3:
2504
3002
  case 12: {
2505
- matchResult_6 = 3;
3003
+ matchResult_7 = 3;
2506
3004
  break;
2507
3005
  }
2508
3006
  case 15: {
2509
- matchResult_6 = 4;
3007
+ matchResult_7 = 4;
2510
3008
  break;
2511
3009
  }
2512
3010
  default:
2513
- matchResult_6 = 5;
3011
+ matchResult_7 = 5;
2514
3012
  }
2515
3013
  break;
2516
3014
  }
2517
3015
  default:
2518
- matchResult_6 = 5;
3016
+ matchResult_7 = 5;
2519
3017
  }
2520
- switch (matchResult_6) {
3018
+ switch (matchResult_7) {
2521
3019
  case 0: {
2522
- const s_12 = compose(unify(typeDefs, keyType_1, Type.TInt, span_19), compose(s2_10, s1_19));
2523
- const tRes_12 = new Type(/* TOption */ 10, [applyType(s_12, itemType_1)]);
2524
- return [s_12, tRes_12, asTyped(expr, tRes_12)];
3020
+ const s_13 = compose(unify(typeDefs, keyType_1, Type.TInt, span_19), compose(s2_10, s1_19));
3021
+ const tRes_12 = new Type(/* TOption */ 10, [applyType(s_13, itemType_1)]);
3022
+ return [s_13, tRes_12, asTyped(expr, tRes_12)];
2525
3023
  }
2526
3024
  case 1: {
2527
- const s_13 = compose(unify(typeDefs, keyType_1, mapKeyType, span_19), compose(s2_10, s1_19));
2528
- ensureSupportedMapKeyType(typeDefs, span_19, applyType(s_13, mapKeyType));
2529
- const tRes_13 = new Type(/* TOption */ 10, [applyType(s_13, valueType_1)]);
2530
- return [s_13, tRes_13, asTyped(expr, tRes_13)];
3025
+ const s_14 = compose(unify(typeDefs, keyType_1, mapKeyType, span_19), compose(s2_10, s1_19));
3026
+ ensureSupportedMapKeyType(typeDefs, span_19, applyType(s_14, mapKeyType));
3027
+ const tRes_13 = new Type(/* TOption */ 10, [applyType(s_14, valueType_1)]);
3028
+ return [s_14, tRes_13, asTyped(expr, tRes_13)];
2531
3029
  }
2532
3030
  case 2: {
2533
3031
  const itemType_2 = Types_freshVar();
2534
- const s_14 = compose(unify(typeDefs, targetType, new Type(/* TList */ 5, [itemType_2]), span_19), compose(s2_10, s1_19));
2535
- const tRes_14 = new Type(/* TOption */ 10, [applyType(s_14, itemType_2)]);
2536
- return [s_14, tRes_14, asTyped(expr, tRes_14)];
3032
+ const s_15 = compose(unify(typeDefs, targetType, new Type(/* TList */ 5, [itemType_2]), span_19), compose(s2_10, s1_19));
3033
+ const tRes_14 = new Type(/* TOption */ 10, [applyType(s_15, itemType_2)]);
3034
+ return [s_15, tRes_14, asTyped(expr, tRes_14)];
2537
3035
  }
2538
3036
  case 3: {
2539
3037
  const valueType_2 = Types_freshVar();
2540
3038
  ensureSupportedMapKeyType(typeDefs, span_19, keyType_1);
2541
- const s_15 = compose(unify(typeDefs, targetType, new Type(/* TMap */ 9, [keyType_1, valueType_2]), span_19), compose(s2_10, s1_19));
2542
- const tRes_15 = new Type(/* TOption */ 10, [applyType(s_15, valueType_2)]);
2543
- return [s_15, tRes_15, asTyped(expr, tRes_15)];
3039
+ const s_16 = compose(unify(typeDefs, targetType, new Type(/* TMap */ 9, [keyType_1, valueType_2]), span_19), compose(s2_10, s1_19));
3040
+ const tRes_15 = new Type(/* TOption */ 10, [applyType(s_16, valueType_2)]);
3041
+ return [s_16, tRes_15, asTyped(expr, tRes_15)];
2544
3042
  }
2545
3043
  case 4:
2546
3044
  throw new TypeException(new TypeError$("Ambiguous index access: annotate the list or map target", span_19));
@@ -2562,9 +3060,9 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2562
3060
  const s2_11 = patternInput_44[0];
2563
3061
  const tv_7 = Types_freshVar();
2564
3062
  const combined_1 = compose(unify(typeDefs, applyType(s2_11, patternInput_44[1]), new Type(/* TFun */ 11, [applyType(s2_11, tLeft), tv_7]), span_20), compose(s2_11, s1_20));
2565
- const s_16 = compose(constrainMapKeyTypes(typeDefs, span_20, applyType(combined_1, new Type(/* TFun */ 11, [tLeft, tv_7]))), combined_1);
2566
- const tRes_16 = applyType(s_16, tv_7);
2567
- return [s_16, tRes_16, asTyped(expr, tRes_16)];
3063
+ const s_17 = compose(constrainMapKeyTypes(typeDefs, span_20, applyType(combined_1, new Type(/* TFun */ 11, [tLeft, tv_7]))), combined_1);
3064
+ const tRes_16 = applyType(s_17, tv_7);
3065
+ return [s_17, tRes_16, asTyped(expr, tRes_16)];
2568
3066
  }
2569
3067
  case "::": {
2570
3068
  const patternInput_45 = inferExpr(telemetry, typeDefs, constructors, env, a);
@@ -2572,9 +3070,9 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2572
3070
  const s1_21 = patternInput_45[0];
2573
3071
  const patternInput_46 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_21, env), b);
2574
3072
  const s2_12 = patternInput_46[0];
2575
- const s_17 = compose(unify(typeDefs, applyType(s2_12, patternInput_46[1]), new Type(/* TList */ 5, [tHead]), span_20), compose(s2_12, s1_21));
2576
- const tRes_17 = applyType(s_17, new Type(/* TList */ 5, [tHead]));
2577
- return [s_17, tRes_17, asTyped(expr, tRes_17)];
3073
+ const s_18 = compose(unify(typeDefs, applyType(s2_12, patternInput_46[1]), new Type(/* TList */ 5, [tHead]), span_20), compose(s2_12, s1_21));
3074
+ const tRes_17 = applyType(s_18, new Type(/* TList */ 5, [tHead]));
3075
+ return [s_18, tRes_17, asTyped(expr, tRes_17)];
2578
3076
  }
2579
3077
  case "@": {
2580
3078
  const patternInput_47 = inferExpr(telemetry, typeDefs, constructors, env, a);
@@ -2583,9 +3081,9 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2583
3081
  const s2_13 = patternInput_48[0];
2584
3082
  const tv_8 = Types_freshVar();
2585
3083
  const s3_10 = unify(typeDefs, applyType(s2_13, patternInput_47[1]), new Type(/* TList */ 5, [tv_8]), span_20);
2586
- const s_18 = compose(unify(typeDefs, applyType(s3_10, applyType(s2_13, patternInput_48[1])), new Type(/* TList */ 5, [applyType(s3_10, tv_8)]), span_20), compose(s3_10, compose(s2_13, s1_22)));
2587
- const tRes_18 = new Type(/* TList */ 5, [applyType(s_18, tv_8)]);
2588
- return [s_18, tRes_18, asTyped(expr, tRes_18)];
3084
+ const s_19 = compose(unify(typeDefs, applyType(s3_10, applyType(s2_13, patternInput_48[1])), new Type(/* TList */ 5, [applyType(s3_10, tv_8)]), span_20), compose(s3_10, compose(s2_13, s1_22)));
3085
+ const tRes_18 = new Type(/* TList */ 5, [applyType(s_19, tv_8)]);
3086
+ return [s_19, tRes_18, asTyped(expr, tRes_18)];
2589
3087
  }
2590
3088
  default: {
2591
3089
  const patternInput_49 = inferExpr(telemetry, typeDefs, constructors, env, a);
@@ -2647,9 +3145,9 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2647
3145
  const s1_25 = patternInput_54[0];
2648
3146
  const patternInput_55 = inferExpr(telemetry, typeDefs, constructors, applyEnv(s1_25, env), expr.fields[1]);
2649
3147
  const s2_15 = patternInput_55[0];
2650
- const s_20 = compose(unify(typeDefs, applyType(s2_15, patternInput_55[1]), new Type(/* TList */ 5, [t1_12]), expr.fields[2]), compose(s2_15, s1_25));
2651
- const tRes_19 = applyType(s_20, new Type(/* TList */ 5, [t1_12]));
2652
- return [s_20, tRes_19, asTyped(expr, tRes_19)];
3148
+ const s_21 = compose(unify(typeDefs, applyType(s2_15, patternInput_55[1]), new Type(/* TList */ 5, [t1_12]), expr.fields[2]), compose(s2_15, s1_25));
3149
+ const tRes_19 = applyType(s_21, new Type(/* TList */ 5, [t1_12]));
3150
+ return [s_21, tRes_19, asTyped(expr, tRes_19)];
2653
3151
  }
2654
3152
  case 24: {
2655
3153
  const span_22 = expr.fields[2];
@@ -2659,9 +3157,9 @@ function inferExprRaw(telemetry, typeDefs, constructors, env, expr) {
2659
3157
  const s2_16 = patternInput_57[0];
2660
3158
  const tv_10 = Types_freshVar();
2661
3159
  const s3_13 = unify(typeDefs, applyType(s2_16, patternInput_56[1]), new Type(/* TList */ 5, [tv_10]), span_22);
2662
- const s_21 = compose(unify(typeDefs, applyType(s3_13, applyType(s2_16, patternInput_57[1])), new Type(/* TList */ 5, [applyType(s3_13, tv_10)]), span_22), compose(s3_13, compose(s2_16, s1_26)));
2663
- const tRes_20 = new Type(/* TList */ 5, [applyType(s_21, tv_10)]);
2664
- return [s_21, tRes_20, asTyped(expr, tRes_20)];
3160
+ const s_22 = compose(unify(typeDefs, applyType(s3_13, applyType(s2_16, patternInput_57[1])), new Type(/* TList */ 5, [applyType(s3_13, tv_10)]), span_22), compose(s3_13, compose(s2_16, s1_26)));
3161
+ const tRes_20 = new Type(/* TList */ 5, [applyType(s_22, tv_10)]);
3162
+ return [s_22, tRes_20, asTyped(expr, tRes_20)];
2665
3163
  }
2666
3164
  default:
2667
3165
  return [emptySubst, Type.TUnit, asTyped(expr, Type.TUnit)];
@@ -2734,18 +3232,37 @@ function topLevelBindingNames(program) {
2734
3232
  case 3:
2735
3233
  return patternBindingNames(_arg.fields[0]);
2736
3234
  case 4:
2737
- return map((tupledArg) => tupledArg[0], _arg.fields[0]);
3235
+ return map_1((tupledArg) => tupledArg[0], _arg.fields[0]);
2738
3236
  default:
2739
3237
  return empty_2();
2740
3238
  }
2741
3239
  }, program);
2742
3240
  }
2743
3241
 
2744
- function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, program) {
2745
- const decls = ofList(append(map((d) => [d.Name, d], typeDefs_1), choose((_arg) => {
2746
- if (_arg.tag === 0) {
2747
- const d_1 = _arg.fields[0];
2748
- return [d_1.Name, d_1];
3242
+ function inferProgramWithExternsRawAndLocals(captureLocalVariables, registration, program) {
3243
+ let hostDefinitions;
3244
+ try {
3245
+ hostDefinitions = typeDefinitions(registration, append(map_1((d) => d.Name, typeDefs_2), choose((_arg) => {
3246
+ if (_arg.tag === 0) {
3247
+ return _arg.fields[0].Name;
3248
+ }
3249
+ else {
3250
+ return undefined;
3251
+ }
3252
+ }, program)));
3253
+ }
3254
+ catch (matchValue) {
3255
+ if (matchValue instanceof EvalException) {
3256
+ throw new TypeException(new TypeError$(matchValue.Data0.Message, matchValue.Data0.Span));
3257
+ }
3258
+ else {
3259
+ throw matchValue;
3260
+ }
3261
+ }
3262
+ const decls = ofList(append(map_1((d_2) => [d_2.Name, d_2], typeDefs_2), choose((_arg_1) => {
3263
+ if (_arg_1.tag === 0) {
3264
+ const d_3 = _arg_1.fields[0];
3265
+ return [d_3.Name, d_3];
2749
3266
  }
2750
3267
  else {
2751
3268
  return undefined;
@@ -2753,21 +3270,21 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2753
3270
  }, program)), {
2754
3271
  Compare: (x, y) => (comparePrimitives(x, y) | 0),
2755
3272
  });
2756
- const typeDefs = map_1((name, d_2) => {
2757
- if (!isEmpty_1(d_2.Cases)) {
2758
- return new Type(/* TUnion */ 13, [name, ofList(map((tupledArg) => {
3273
+ const typeDefs_1 = fold_1((acc, name_1, t_1) => add(name_1, t_1, acc), map((name, d_4) => {
3274
+ if (!isEmpty_1(d_4.Cases)) {
3275
+ return new Type(/* TUnion */ 13, [name, ofList(map_1((tupledArg) => {
2759
3276
  let option_1;
2760
3277
  return [tupledArg[0], (option_1 = tupledArg[1], (option_1 != null) ? typeFromRef(decls, singleton(name), option_1) : undefined)];
2761
- }, d_2.Cases), {
3278
+ }, d_4.Cases), {
2762
3279
  Compare: (x_1, y_1) => (comparePrimitives(x_1, y_1) | 0),
2763
3280
  })]);
2764
3281
  }
2765
3282
  else {
2766
- return new Type(/* TRecord */ 8, [ofList(map((tupledArg_1) => [tupledArg_1[0], typeFromRef(decls, singleton(d_2.Name), tupledArg_1[1])], d_2.Fields), {
3283
+ return new Type(/* TRecord */ 8, [ofList(map_1((tupledArg_1) => [tupledArg_1[0], typeFromRef(decls, singleton(d_4.Name), tupledArg_1[1])], d_4.Fields), {
2767
3284
  Compare: (x_2, y_2) => (comparePrimitives(x_2, y_2) | 0),
2768
3285
  })]);
2769
3286
  }
2770
- }, decls);
3287
+ }, decls), hostDefinitions);
2771
3288
  const constructors = ofList(collect((tupledArg_2) => {
2772
3289
  const typeName = tupledArg_2[0];
2773
3290
  return collect((tupledArg_3) => {
@@ -2779,13 +3296,13 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2779
3296
  }, toList(decls)), {
2780
3297
  Compare: (x_3, y_3) => (comparePrimitives(x_3, y_3) | 0),
2781
3298
  });
2782
- const constructorSchemes = map((tupledArg_4) => {
2783
- let matchValue;
3299
+ const constructorSchemes = map_1((tupledArg_4) => {
3300
+ let matchValue_1;
2784
3301
  const sigInfo_1 = tupledArg_4[1];
2785
3302
  const unionType = new Type(/* TNamed */ 12, [sigInfo_1.UnionName]);
2786
- return [tupledArg_4[0], new Scheme(empty_2(), (matchValue = sigInfo_1.Payload, (matchValue != null) ? (new Type(/* TFun */ 11, [matchValue, unionType])) : unionType))];
3303
+ return [tupledArg_4[0], new Scheme(empty_2(), (matchValue_1 = sigInfo_1.Payload, (matchValue_1 != null) ? (new Type(/* TFun */ 11, [matchValue_1, unionType])) : unionType))];
2787
3304
  }, toList(constructors));
2788
- let env = fold((acc, tupledArg_5) => FSharpMap__Add(acc, tupledArg_5[0], tupledArg_5[1]), envFromExterns(externs), constructorSchemes);
3305
+ let env = fold((acc_1, tupledArg_5) => FSharpMap__Add(acc_1, tupledArg_5[0], tupledArg_5[1]), envFromExterns(registration.Functions), constructorSchemes);
2789
3306
  const telemetry = captureLocalVariables ? createTelemetry() : undefined;
2790
3307
  const typed = [];
2791
3308
  try {
@@ -2803,44 +3320,44 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2803
3320
  case 2: {
2804
3321
  const span_1 = stmt.fields[6];
2805
3322
  const returnAnnotation = stmt.fields[2];
2806
- const name_2 = stmt.fields[0];
3323
+ const name_3 = stmt.fields[0];
2807
3324
  const isExported = stmt.fields[5];
2808
- const exprVal = foldBack((arg, acc_1) => (new Expr(/* ELambda */ 4, [arg, acc_1, span_1])), stmt.fields[1], stmt.fields[3]);
3325
+ const exprVal = foldBack((arg, acc_2) => (new Expr(/* ELambda */ 4, [arg, acc_2, span_1])), stmt.fields[1], stmt.fields[3]);
2809
3326
  let startIndex;
2810
3327
  if (telemetry == null) {
2811
3328
  startIndex = 0;
2812
3329
  }
2813
3330
  else {
2814
- const t_1 = telemetry;
2815
- startIndex = t_1.LocalVariableTypes.length;
3331
+ const t_2 = telemetry;
3332
+ startIndex = t_2.LocalVariableTypes.length;
2816
3333
  }
2817
3334
  if (stmt.fields[4]) {
2818
3335
  const tv = Types_freshVar();
2819
- const patternInput = inferExpr(telemetry, typeDefs, constructors, add(name_2, new Scheme(empty_2(), tv), env), exprVal);
3336
+ const patternInput = inferExpr(telemetry, typeDefs_1, constructors, add(name_3, new Scheme(empty_2(), tv), env), exprVal);
2820
3337
  const t1 = patternInput[1];
2821
3338
  const s1 = patternInput[0];
2822
- const s2 = unify(typeDefs, applyType(s1, tv), t1, span_1);
2823
- const s = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn = annotationTypeFromRef(typeDefs, span_1, returnAnnotation), unify(typeDefs, functionReturnType(applyType(s2, t1)), expectedReturn, span_1))), compose(s2, s1));
3339
+ const s2 = unify(typeDefs_1, applyType(s1, tv), t1, span_1);
3340
+ const s = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn = annotationTypeFromRef(typeDefs_1, span_1, returnAnnotation), unify(typeDefs_1, functionReturnType(applyType(s2, t1)), expectedReturn, span_1))), compose(s2, s1));
2824
3341
  applySubstToCapturedLocals(telemetry, startIndex, s);
2825
3342
  const env$0027 = applyEnv(s, env);
2826
3343
  const inferred = applyType(s, t1);
2827
- validateMapKeyTypes(typeDefs, span_1, inferred);
3344
+ validateMapKeyTypes(typeDefs_1, span_1, inferred);
2828
3345
  const scheme_1 = Types_generalize(env$0027, inferred);
2829
- env = add(name_2, scheme_1, env$0027);
2830
- void (typed.push(new TypedStmt(/* TSLet */ 1, [name_2, exprVal, inferred, true, isExported, span_1])));
3346
+ env = add(name_3, scheme_1, env$0027);
3347
+ void (typed.push(new TypedStmt(/* TSLet */ 1, [name_3, exprVal, inferred, true, isExported, span_1])));
2831
3348
  }
2832
3349
  else {
2833
- const patternInput_1 = inferExpr(telemetry, typeDefs, constructors, env, exprVal);
3350
+ const patternInput_1 = inferExpr(telemetry, typeDefs_1, constructors, env, exprVal);
2834
3351
  const t1_1 = patternInput_1[1];
2835
3352
  const s1_1 = patternInput_1[0];
2836
- const s_1 = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn_1 = annotationTypeFromRef(typeDefs, span_1, returnAnnotation), unify(typeDefs, functionReturnType(applyType(s1_1, t1_1)), expectedReturn_1, span_1))), s1_1);
3353
+ const s_1 = compose((returnAnnotation == null) ? emptySubst : ((expectedReturn_1 = annotationTypeFromRef(typeDefs_1, span_1, returnAnnotation), unify(typeDefs_1, functionReturnType(applyType(s1_1, t1_1)), expectedReturn_1, span_1))), s1_1);
2837
3354
  applySubstToCapturedLocals(telemetry, startIndex, s_1);
2838
3355
  const env$0027_1 = applyEnv(s_1, env);
2839
3356
  const inferred_1 = applyType(s_1, t1_1);
2840
- validateMapKeyTypes(typeDefs, span_1, inferred_1);
3357
+ validateMapKeyTypes(typeDefs_1, span_1, inferred_1);
2841
3358
  const scheme_2 = Types_generalize(env$0027_1, inferred_1);
2842
- env = add(name_2, scheme_2, env$0027_1);
2843
- void (typed.push(new TypedStmt(/* TSLet */ 1, [name_2, exprVal, inferred_1, false, isExported, span_1])));
3359
+ env = add(name_3, scheme_2, env$0027_1);
3360
+ void (typed.push(new TypedStmt(/* TSLet */ 1, [name_3, exprVal, inferred_1, false, isExported, span_1])));
2844
3361
  }
2845
3362
  break;
2846
3363
  }
@@ -2853,20 +3370,20 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2853
3370
  startIndex_1 = 0;
2854
3371
  }
2855
3372
  else {
2856
- const t_2 = telemetry;
2857
- startIndex_1 = t_2.LocalVariableTypes.length;
3373
+ const t_3 = telemetry;
3374
+ startIndex_1 = t_3.LocalVariableTypes.length;
2858
3375
  }
2859
- const patternInput_2 = inferExpr(telemetry, typeDefs, constructors, env, expr_1);
3376
+ const patternInput_2 = inferExpr(telemetry, typeDefs_1, constructors, env, expr_1);
2860
3377
  const s1_2 = patternInput_2[0];
2861
- const patternInput_3 = inferPattern(telemetry, typeDefs, constructors, pattern);
2862
- const s_2 = compose(unify(typeDefs, applyType(s1_2, patternInput_2[1]), patternInput_3[1], span_2), s1_2);
3378
+ const patternInput_3 = inferPattern(telemetry, typeDefs_1, constructors, pattern);
3379
+ const s_2 = compose(unify(typeDefs_1, applyType(s1_2, patternInput_2[1]), patternInput_3[1], span_2), s1_2);
2863
3380
  applySubstToCapturedLocals(telemetry, startIndex_1, s_2);
2864
3381
  const envBase = applyEnv(s_2, env);
2865
- const typedBindings = map_1((_arg_1, ty) => applyType(s_2, ty), patternInput_3[0]);
2866
- iterate_2((_arg_2, ty_1) => {
2867
- validateMapKeyTypes(typeDefs, span_2, ty_1);
3382
+ const typedBindings = map((_arg_2, ty) => applyType(s_2, ty), patternInput_3[0]);
3383
+ iterate_2((_arg_3, ty_1) => {
3384
+ validateMapKeyTypes(typeDefs_1, span_2, ty_1);
2868
3385
  }, typedBindings);
2869
- env = fold_1((state_1, name_3, bindingType) => add(name_3, Types_generalize(envBase, bindingType), state_1), envBase, typedBindings);
3386
+ env = fold_1((state_1, name_4, bindingType) => add(name_4, Types_generalize(envBase, bindingType), state_1), envBase, typedBindings);
2870
3387
  void (typed.push(new TypedStmt(/* TSLetPattern */ 2, [pattern, expr_1, typedBindings, stmt.fields[2], span_2])));
2871
3388
  break;
2872
3389
  }
@@ -2877,29 +3394,29 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2877
3394
  startIndex_2 = 0;
2878
3395
  }
2879
3396
  else {
2880
- const t_3 = telemetry;
2881
- startIndex_2 = t_3.LocalVariableTypes.length;
3397
+ const t_4 = telemetry;
3398
+ startIndex_2 = t_4.LocalVariableTypes.length;
2882
3399
  }
2883
- const foldedBindings = map((tupledArg_6) => {
3400
+ const foldedBindings = map_1((tupledArg_6) => {
2884
3401
  const args_1 = tupledArg_6[1];
2885
3402
  const bindingSpan = tupledArg_6[4];
2886
3403
  if (isEmpty_1(args_1)) {
2887
3404
  throw new TypeException(new TypeError$("\'let rec ... and ...\' requires function arguments for each binding", bindingSpan));
2888
3405
  }
2889
- return [tupledArg_6[0], tupledArg_6[2], foldBack((arg_1, acc_2) => (new Expr(/* ELambda */ 4, [arg_1, acc_2, bindingSpan])), args_1, tupledArg_6[3]), bindingSpan];
3406
+ return [tupledArg_6[0], tupledArg_6[2], foldBack((arg_1, acc_3) => (new Expr(/* ELambda */ 4, [arg_1, acc_3, bindingSpan])), args_1, tupledArg_6[3]), bindingSpan];
2890
3407
  }, stmt.fields[0]);
2891
- const freshByName = ofList(map((tupledArg_7) => [tupledArg_7[0], Types_freshVar()], foldedBindings), {
3408
+ const freshByName = ofList(map_1((tupledArg_7) => [tupledArg_7[0], Types_freshVar()], foldedBindings), {
2892
3409
  Compare: (x_4, y_4) => (comparePrimitives(x_4, y_4) | 0),
2893
3410
  });
2894
- const envRec_1 = fold_1((acc_3, name_6, tv_1) => add(name_6, new Scheme(empty_2(), tv_1), acc_3), env, freshByName);
3411
+ const envRec_1 = fold_1((acc_4, name_7, tv_1) => add(name_7, new Scheme(empty_2(), tv_1), acc_4), env, freshByName);
2895
3412
  let sRec = emptySubst;
2896
3413
  const enumerator_1 = getEnumerator(foldedBindings);
2897
3414
  try {
2898
3415
  while (enumerator_1["System.Collections.IEnumerator.MoveNext"]()) {
2899
3416
  const forLoopVar_1 = enumerator_1["System.Collections.Generic.IEnumerator`1.get_Current"]();
2900
- const patternInput_4 = inferExpr(telemetry, typeDefs, constructors, applyEnv(sRec, envRec_1), forLoopVar_1[2]);
3417
+ const patternInput_4 = inferExpr(telemetry, typeDefs_1, constructors, applyEnv(sRec, envRec_1), forLoopVar_1[2]);
2901
3418
  const s1_3 = patternInput_4[0];
2902
- const s2_2 = unify(typeDefs, applyType(s1_3, applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar_1[0]))), patternInput_4[1], forLoopVar_1[3]);
3419
+ const s2_2 = unify(typeDefs_1, applyType(s1_3, applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar_1[0]))), patternInput_4[1], forLoopVar_1[3]);
2903
3420
  sRec = compose(s2_2, compose(s1_3, sRec));
2904
3421
  }
2905
3422
  }
@@ -2915,8 +3432,8 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2915
3432
  if (returnAnnotation_2 == null) {
2916
3433
  }
2917
3434
  else {
2918
- const expectedReturn_2 = annotationTypeFromRef(typeDefs, bindingSpan_2, returnAnnotation_2);
2919
- const sRet_2 = unify(typeDefs, functionReturnType(applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar_2[0]))), expectedReturn_2, bindingSpan_2);
3435
+ const expectedReturn_2 = annotationTypeFromRef(typeDefs_1, bindingSpan_2, returnAnnotation_2);
3436
+ const sRet_2 = unify(typeDefs_1, functionReturnType(applyType(sRec, FSharpMap__get_Item(freshByName, forLoopVar_2[0]))), expectedReturn_2, bindingSpan_2);
2920
3437
  sRec = compose(sRet_2, sRec);
2921
3438
  }
2922
3439
  }
@@ -2926,17 +3443,17 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2926
3443
  }
2927
3444
  applySubstToCapturedLocals(telemetry, startIndex_2, sRec);
2928
3445
  const envGeneralize = applyEnv(sRec, env);
2929
- const schemes = map((tupledArg_8) => {
2930
- const name_9 = tupledArg_8[0];
2931
- const inferred_2 = applyType(sRec, FSharpMap__get_Item(freshByName, name_9));
2932
- validateMapKeyTypes(typeDefs, span_3, inferred_2);
2933
- return [name_9, Types_generalize(envGeneralize, inferred_2)];
3446
+ const schemes = map_1((tupledArg_8) => {
3447
+ const name_10 = tupledArg_8[0];
3448
+ const inferred_2 = applyType(sRec, FSharpMap__get_Item(freshByName, name_10));
3449
+ validateMapKeyTypes(typeDefs_1, span_3, inferred_2);
3450
+ return [name_10, Types_generalize(envGeneralize, inferred_2)];
2934
3451
  }, foldedBindings);
2935
- const typedBindings_1 = map((tupledArg_9) => {
2936
- const name_10 = tupledArg_9[0];
2937
- return [name_10, tupledArg_9[2], applyType(sRec, FSharpMap__get_Item(freshByName, name_10)), tupledArg_9[3]];
3452
+ const typedBindings_1 = map_1((tupledArg_9) => {
3453
+ const name_11 = tupledArg_9[0];
3454
+ return [name_11, tupledArg_9[2], applyType(sRec, FSharpMap__get_Item(freshByName, name_11)), tupledArg_9[3]];
2938
3455
  }, foldedBindings);
2939
- env = fold((acc_4, tupledArg_10) => add(tupledArg_10[0], tupledArg_10[1], acc_4), envGeneralize, schemes);
3456
+ env = fold((acc_5, tupledArg_10) => add(tupledArg_10[0], tupledArg_10[1], acc_5), envGeneralize, schemes);
2940
3457
  void (typed.push(new TypedStmt(/* TSLetRecGroup */ 3, [typedBindings_1, stmt.fields[1], span_3])));
2941
3458
  break;
2942
3459
  }
@@ -2947,15 +3464,15 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2947
3464
  startIndex_3 = 0;
2948
3465
  }
2949
3466
  else {
2950
- const t_4 = telemetry;
2951
- startIndex_3 = t_4.LocalVariableTypes.length;
3467
+ const t_5 = telemetry;
3468
+ startIndex_3 = t_5.LocalVariableTypes.length;
2952
3469
  }
2953
- const patternInput_5 = inferExpr(telemetry, typeDefs, constructors, env, expr_2);
3470
+ const patternInput_5 = inferExpr(telemetry, typeDefs_1, constructors, env, expr_2);
2954
3471
  const t1_3 = patternInput_5[1];
2955
3472
  const s1_4 = patternInput_5[0];
2956
- const s_3 = compose((forLoopVar[0] < (length(program) - 1)) ? unify(typeDefs, applyType(s1_4, t1_3), Type.TUnit, Ast_spanOfExpr(expr_2)) : emptySubst, s1_4);
3473
+ const s_3 = compose((forLoopVar[0] < (length(program) - 1)) ? unify(typeDefs_1, applyType(s1_4, t1_3), Type.TUnit, Ast_spanOfExpr(expr_2)) : emptySubst, s1_4);
2957
3474
  applySubstToCapturedLocals(telemetry, startIndex_3, s_3);
2958
- validateMapKeyTypes(typeDefs, Ast_spanOfExpr(expr_2), applyType(s_3, t1_3));
3475
+ validateMapKeyTypes(typeDefs_1, Ast_spanOfExpr(expr_2), applyType(s_3, t1_3));
2959
3476
  env = applyEnv(s_3, env);
2960
3477
  void (typed.push(new TypedStmt(/* TSExpr */ 4, [patternInput_5[2]])));
2961
3478
  break;
@@ -2970,13 +3487,13 @@ function inferProgramWithExternsRawAndLocals(captureLocalVariables, externs, pro
2970
3487
  }
2971
3488
  return [toList_1(typed), capturedLocalVariableTypes(telemetry)];
2972
3489
  }
2973
- catch (matchValue_1) {
2974
- throw matchValue_1;
3490
+ catch (matchValue_2) {
3491
+ throw matchValue_2;
2975
3492
  }
2976
3493
  }
2977
3494
 
2978
3495
  export function inferProgramWithExternsRaw(externs, program) {
2979
- return inferProgramWithExternsRawAndLocals(false, externs, program)[0];
3496
+ return inferProgramWithExternsRawAndLocals(false, ofExterns(externs), program)[0];
2980
3497
  }
2981
3498
 
2982
3499
  export function inferProgramWithExterns(externs, program) {
@@ -3000,7 +3517,7 @@ export function inferProgramWithExternsAndLocalVariableTypes(externs, program) {
3000
3517
  if (option_3 != null) {
3001
3518
  throw new TypeException(new TypeError$(concat("Top-level binding \'", option_3, "\' collides with reserved stdlib symbol"), unknownSpan));
3002
3519
  }
3003
- return inferProgramWithExternsRawAndLocals(true, externs, program);
3520
+ return inferProgramWithExternsRawAndLocals(true, ofExterns(externs), program);
3004
3521
  }
3005
3522
 
3006
3523
  export function inferProgramWithLocalVariableTypes(program) {
@@ -3011,3 +3528,23 @@ export function inferProgram(program) {
3011
3528
  return inferProgramWithExterns(empty_2(), program);
3012
3529
  }
3013
3530
 
3531
+ export function inferProgramWithRegistration(registration, program) {
3532
+ if (exists((ext) => contains(ext.Name, builtinReservedNames), registration.Functions)) {
3533
+ throw new TypeException(new TypeError$("Host extern collides with reserved stdlib symbol", unknownSpan));
3534
+ }
3535
+ if (exists((name) => contains(name, builtinReservedNames), topLevelBindingNames(program))) {
3536
+ throw new TypeException(new TypeError$("Top-level binding collides with reserved stdlib symbol", unknownSpan));
3537
+ }
3538
+ return inferProgramWithExternsRawAndLocals(false, registration, program)[0];
3539
+ }
3540
+
3541
+ export function inferProgramWithRegistrationAndLocalVariableTypes(registration, program) {
3542
+ if (exists((ext) => contains(ext.Name, builtinReservedNames), registration.Functions)) {
3543
+ throw new TypeException(new TypeError$("Host extern collides with reserved stdlib symbol", unknownSpan));
3544
+ }
3545
+ if (exists((name) => contains(name, builtinReservedNames), topLevelBindingNames(program))) {
3546
+ throw new TypeException(new TypeError$("Top-level binding collides with reserved stdlib symbol", unknownSpan));
3547
+ }
3548
+ return inferProgramWithExternsRawAndLocals(true, registration, program);
3549
+ }
3550
+