unison/unison-src/transcripts/fix2254.md

94 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

``` ucm :hide
2024-06-26 21:12:15 +03:00
scratch/a> builtins.merge lib.builtins
2021-07-21 00:41:59 +03:00
```
2021-07-23 18:46:51 +03:00
This transcript checks that updates to data types propagate successfully to dependent types and dependent terms that do pattern matching. First let's create some types and terms:
``` unison :hide
unique type A a b c d
2021-07-21 00:41:59 +03:00
= A a
| B b
| C c
| D d
2021-08-24 00:05:37 +03:00
structural type NeedsA a b = NeedsA (A a b Nat Nat)
2021-07-23 17:47:48 +03:00
| Zoink Text
2021-07-22 23:52:39 +03:00
2021-07-21 00:41:59 +03:00
f : A Nat Nat Nat Nat -> Nat
f = cases
A n -> n
_ -> 42
f2 a =
n = f a
n + 1
2021-07-22 23:52:39 +03:00
f3 : NeedsA Nat Nat -> Nat
f3 = cases
NeedsA a -> f a + 20
2021-07-23 17:47:48 +03:00
_ -> 0
2021-07-22 23:52:39 +03:00
2021-07-21 00:41:59 +03:00
g : A Nat Nat Nat Nat -> Nat
g = cases
D n -> n
_ -> 43
```
2024-06-26 21:12:15 +03:00
We'll make our edits in a new branch.
2021-07-23 18:46:51 +03:00
``` ucm
2024-06-26 21:12:15 +03:00
scratch/a> add
2024-07-11 22:45:18 +03:00
scratch/a> branch /a2
2024-06-26 21:12:15 +03:00
scratch/a2>
2021-07-21 00:41:59 +03:00
```
2021-07-23 18:46:51 +03:00
First let's edit the `A` type, adding another constructor `E`. Note that the functions written against the old type have a wildcard in their pattern match, so they should work fine after the update.
``` unison :hide
unique type A a b c d
2021-07-21 00:41:59 +03:00
= A a
| B b
| C c
| D d
| E a d
```
2021-07-23 18:46:51 +03:00
Let's do the update now, and verify that the definitions all look good and there's nothing `todo`:
``` ucm
2024-07-11 22:45:18 +03:00
scratch/a2> update
2024-06-26 21:12:15 +03:00
scratch/a2> view A NeedsA f f2 f3 g
scratch/a2> todo
2022-04-07 00:12:07 +03:00
```
2021-07-23 18:46:51 +03:00
## Record updates
Here's a test of updating a record:
``` ucm :hide
2024-06-26 21:12:15 +03:00
scratch/r1> builtins.merge lib.builtins
```
``` unison
2021-08-24 00:05:37 +03:00
structural type Rec = { uno : Nat, dos : Nat }
combine r = uno r + dos r
```
``` ucm
2024-06-26 21:12:15 +03:00
scratch/r1> add
scratch/r1> branch r2
2024-01-12 20:39:18 +03:00
```
``` unison
2021-08-24 00:05:37 +03:00
structural type Rec = { uno : Nat, dos : Nat, tres : Text }
```
2021-07-23 18:46:51 +03:00
And checking that after updating this record, there's nothing `todo`:
``` ucm
2024-07-11 22:45:18 +03:00
scratch/r2> update
2024-06-26 21:12:15 +03:00
scratch/r2> todo
```