2019-10-23 19:51:35 +03:00
|
|
|
# Propagating type edits
|
|
|
|
|
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
|
|
|
|
use .builtin
|
|
|
|
|
2019-10-30 20:20:59 +03:00
|
|
|
unique [foo1] 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
|
|
|
|
.subpath> add
|
|
|
|
.subpath> find.verbose
|
|
|
|
.subpath> view fooToInt
|
|
|
|
```
|
|
|
|
|
2019-10-23 22:27:35 +03:00
|
|
|
Then if we change the type `Foo`...
|
|
|
|
|
2019-10-23 19:51:35 +03:00
|
|
|
```unison
|
2019-10-30 20:20:59 +03:00
|
|
|
unique [foo2] 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
|
|
|
|
.subpath> update
|
|
|
|
```
|
|
|
|
|
2019-10-23 22:27:35 +03:00
|
|
|
... it should automatically propagate the type to `fooToInt`.
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
.subpath> view fooToInt
|
|
|
|
```
|
|
|
|
|
|
|
|
### 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
|
|
|
|
use .builtin
|
|
|
|
|
|
|
|
someTerm : Optional foo -> Optional foo
|
|
|
|
someTerm x = x
|
|
|
|
|
|
|
|
otherTerm : Optional baz -> Optional baz
|
|
|
|
otherTerm y = someTerm y
|
|
|
|
```
|
|
|
|
|
|
|
|
Add that to the codebase:
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
.subpath.preserve> add
|
|
|
|
```
|
|
|
|
|
|
|
|
Let's now edit the dependency:
|
|
|
|
|
|
|
|
```unison
|
|
|
|
use .builtin
|
|
|
|
|
|
|
|
someTerm : Optional x -> Optional x
|
|
|
|
someTerm _ = None
|
|
|
|
```
|
|
|
|
|
|
|
|
Update...
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
.subpath.preserve> update
|
|
|
|
```
|
|
|
|
|
|
|
|
Now the type of `someTerm` should be `Optional x -> Optional x` and the
|
|
|
|
type of `otherTerm` should remain the same.
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
.subpath.preserve> view someTerm
|
|
|
|
.subpath.preserve> view otherTerm
|
|
|
|
```
|
2019-10-24 22:19:57 +03:00
|
|
|
|
|
|
|
### Propagation only applies to the local branch
|
|
|
|
|
2019-10-30 18:42:32 +03:00
|
|
|
Cleaning up a bit...
|
|
|
|
|
2019-10-24 22:19:57 +03:00
|
|
|
```ucm
|
|
|
|
.> delete.namespace subpath
|
|
|
|
```
|
|
|
|
|
2019-10-30 18:42:32 +03:00
|
|
|
Now, we make two terms, where one depends on the other.
|
|
|
|
|
2019-10-24 22:19:57 +03:00
|
|
|
```unison
|
|
|
|
use .builtin
|
|
|
|
|
|
|
|
someTerm : Optional foo -> Optional foo
|
|
|
|
someTerm x = x
|
|
|
|
|
|
|
|
otherTerm : Optional baz -> Optional baz
|
|
|
|
otherTerm y = someTerm y
|
|
|
|
```
|
|
|
|
|
2019-10-30 18:42:32 +03:00
|
|
|
We'll make two copies of this namespace.
|
|
|
|
|
2019-10-24 22:19:57 +03:00
|
|
|
```ucm
|
|
|
|
.subpath.one> add
|
|
|
|
.subpath> fork one two
|
|
|
|
```
|
|
|
|
|
2019-10-30 18:42:32 +03:00
|
|
|
Now let's edit one of the terms...
|
|
|
|
|
2019-10-24 22:19:57 +03:00
|
|
|
```unison
|
|
|
|
use .builtin
|
|
|
|
|
|
|
|
someTerm : Optional x -> Optional x
|
|
|
|
someTerm _ = None
|
|
|
|
```
|
|
|
|
|
2019-10-30 18:42:32 +03:00
|
|
|
... in one of the namespaces...
|
|
|
|
|
2019-10-24 22:19:57 +03:00
|
|
|
```ucm
|
|
|
|
.subpath.one> update
|
|
|
|
```
|
|
|
|
|
2019-10-30 18:42:32 +03:00
|
|
|
The other namespace should be left alone.
|
|
|
|
|
2019-10-24 22:19:57 +03:00
|
|
|
```ucm
|
|
|
|
.subpath.two> view someTerm
|
|
|
|
```
|
|
|
|
|