2019-10-23 19:51:35 +03:00
|
|
|
# Propagating type edits
|
|
|
|
|
2020-02-13 18:59:53 +03:00
|
|
|
```ucm:hide
|
2024-06-26 21:49:49 +03:00
|
|
|
scratch/main> builtins.merge lib.builtins
|
2020-02-13 18:59:53 +03:00
|
|
|
```
|
|
|
|
|
2019-10-23 22:27:35 +03:00
|
|
|
We introduce a type `Foo` with a function dependent `fooToInt`.
|
|
|
|
|
2019-10-23 19:51:35 +03:00
|
|
|
```unison
|
2020-02-17 07:56:29 +03:00
|
|
|
unique type Foo = Foo
|
2019-10-23 19:51:35 +03:00
|
|
|
|
|
|
|
fooToInt : Foo -> Int
|
|
|
|
fooToInt _ = +42
|
|
|
|
```
|
|
|
|
|
2019-10-23 22:27:35 +03:00
|
|
|
And then we add it.
|
|
|
|
|
2019-10-23 19:51:35 +03:00
|
|
|
```ucm
|
2024-06-26 21:49:49 +03:00
|
|
|
scratch/main> add
|
|
|
|
scratch/main> find.verbose
|
|
|
|
scratch/main> view fooToInt
|
2019-10-23 19:51:35 +03:00
|
|
|
```
|
|
|
|
|
2019-10-23 22:27:35 +03:00
|
|
|
Then if we change the type `Foo`...
|
|
|
|
|
2019-10-23 19:51:35 +03:00
|
|
|
```unison
|
2020-02-17 07:56:29 +03:00
|
|
|
unique type Foo = Foo | Bar
|
2019-10-23 19:51:35 +03:00
|
|
|
```
|
|
|
|
|
2019-10-23 22:27:35 +03:00
|
|
|
and update the codebase to use the new type `Foo`...
|
|
|
|
|
2019-10-23 19:51:35 +03:00
|
|
|
```ucm
|
2024-06-26 21:49:49 +03:00
|
|
|
scratch/main> update.old
|
2019-10-23 19:51:35 +03:00
|
|
|
```
|
|
|
|
|
2019-10-23 22:27:35 +03:00
|
|
|
... it should automatically propagate the type to `fooToInt`.
|
|
|
|
|
|
|
|
```ucm
|
2024-06-26 21:49:49 +03:00
|
|
|
scratch/main> view fooToInt
|
2019-10-23 22:27:35 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### Preserving user type variables
|
|
|
|
|
|
|
|
We make a term that has a dependency on another term and also a non-redundant
|
|
|
|
user-provided type signature.
|
|
|
|
|
|
|
|
```unison
|
2024-01-09 01:42:09 +03:00
|
|
|
preserve.someTerm : Optional foo -> Optional foo
|
|
|
|
preserve.someTerm x = x
|
2019-10-23 22:27:35 +03:00
|
|
|
|
2024-01-09 01:42:09 +03:00
|
|
|
preserve.otherTerm : Optional baz -> Optional baz
|
|
|
|
preserve.otherTerm y = someTerm y
|
2019-10-23 22:27:35 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Add that to the codebase:
|
|
|
|
|
|
|
|
```ucm
|
2024-06-26 21:49:49 +03:00
|
|
|
scratch/main> add
|
2019-10-23 22:27:35 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Let's now edit the dependency:
|
|
|
|
|
|
|
|
```unison
|
2024-01-09 01:42:09 +03:00
|
|
|
preserve.someTerm : Optional x -> Optional x
|
|
|
|
preserve.someTerm _ = None
|
2019-10-23 22:27:35 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
Update...
|
|
|
|
|
|
|
|
```ucm
|
2024-06-26 21:49:49 +03:00
|
|
|
scratch/main> update.old
|
2019-10-23 22:27:35 +03:00
|
|
|
```
|
|
|
|
|
2020-02-13 18:59:53 +03:00
|
|
|
Now the type of `someTerm` should be `Optional x -> Optional x` and the
|
2019-10-23 22:27:35 +03:00
|
|
|
type of `otherTerm` should remain the same.
|
|
|
|
|
|
|
|
```ucm
|
2024-06-26 21:49:49 +03:00
|
|
|
scratch/main> view preserve.someTerm
|
|
|
|
scratch/main> view preserve.otherTerm
|
2019-10-23 22:27:35 +03:00
|
|
|
```
|