Commit 73cf47d
committed
Experiment for untagged pattern matching.
First step: remove the distinction between cases with and without payload in the toplevel algorithm.
On this test:
```res
@unboxed
type rec t =
| Boolean(bool)
| @as(null) Null
| String(string)
| Number(float)
| Object(Dict.t<t>)
| Array(array<t>)
type group = {
id: string,
name: string,
}
let decodeGroup = group => {
switch group {
| (dict{"id": String(id), "name": String(name)}) =>
(id, name)
| _ => ("e", "f")
}
}
```
Before:
```js
function decodeGroup(group) {
let match = group.id;
if (match === undefined) {
return [
"e",
"f"
];
}
if (match === null) {
return [
"e",
"f"
];
}
if (typeof match !== "string") {
return [
"e",
"f"
];
}
let match$1 = group.name;
if (match$1 !== undefined && !(match$1 === null || typeof match$1 !== "string")) {
return [
match,
match$1
];
} else {
return [
"e",
"f"
];
}
}
```
After:
```
function decodeGroup(group) {
let match = group.id;
if (match === undefined) {
return [
"e",
"f"
];
}
if (typeof match !== "string") {
return [
"e",
"f"
];
}
let match$1 = group.name;
if (match$1 !== undefined && typeof match$1 === "string") {
return [
match,
match$1
];
} else {
return [
"e",
"f"
];
}
}
```
The 3 cases have become 2: check for optional fields and check for which case it is.1 parent 1a3efbe commit 73cf47d
1 file changed
+52
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
| 676 | + | |
| 677 | + | |
676 | 678 | | |
677 | 679 | | |
678 | 680 | | |
| |||
713 | 715 | | |
714 | 716 | | |
715 | 717 | | |
| 718 | + | |
716 | 719 | | |
717 | 720 | | |
718 | 721 | | |
719 | 722 | | |
| 723 | + | |
720 | 724 | | |
721 | 725 | | |
722 | 726 | | |
| 727 | + | |
723 | 728 | | |
724 | 729 | | |
725 | 730 | | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
730 | 740 | | |
731 | 741 | | |
732 | 742 | | |
733 | 743 | | |
734 | 744 | | |
735 | | - | |
736 | | - | |
737 | | - | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
743 | 771 | | |
744 | 772 | | |
745 | | - | |
| 773 | + | |
746 | 774 | | |
747 | 775 | | |
748 | 776 | | |
749 | | - | |
| 777 | + | |
750 | 778 | | |
751 | 779 | | |
752 | 780 | | |
| |||
756 | 784 | | |
757 | 785 | | |
758 | 786 | | |
| 787 | + | |
| 788 | + | |
759 | 789 | | |
760 | | - | |
761 | | - | |
| 790 | + | |
762 | 791 | | |
763 | 792 | | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
768 | 800 | | |
769 | 801 | | |
770 | 802 | | |
| |||
0 commit comments