unison/unison-src/transcripts/propagate.md
2024-01-08 14:42:09 -08:00

2.0 KiB

Propagating type edits

.subpath.lib> builtins.merge

We introduce a type Foo with a function dependent fooToInt.

unique type Foo = Foo

fooToInt : Foo -> Int
fooToInt _ = +42

And then we add it.

.subpath> add
.subpath> find.verbose
.subpath> view fooToInt

Then if we change the type Foo...

unique type Foo = Foo | Bar

and update the codebase to use the new type Foo...

.subpath> update.old

... it should automatically propagate the type to fooToInt.

.subpath> view fooToInt
.> cd .

Preserving user type variables

We make a term that has a dependency on another term and also a non-redundant user-provided type signature.

preserve.someTerm : Optional foo -> Optional foo
preserve.someTerm x = x

preserve.otherTerm : Optional baz -> Optional baz
preserve.otherTerm y = someTerm y

Add that to the codebase:

.subpath> add
.> cd .

Let's now edit the dependency:

preserve.someTerm : Optional x -> Optional x
preserve.someTerm _ = None

Update...

.subpath> update.old
.> cd .

Now the type of someTerm should be Optional x -> Optional x and the type of otherTerm should remain the same.

.subpath> view preserve.someTerm
.subpath> view preserve.otherTerm

Propagation only applies to the local branch

Cleaning up a bit...

.> delete.namespace subpath
.subpath.lib> builtins.merge

Now, we make two terms, where one depends on the other.

one.someTerm : Optional foo -> Optional foo
one.someTerm x = x

one.otherTerm : Optional baz -> Optional baz
one.otherTerm y = someTerm y

We'll make two copies of this namespace.

.subpath> add
.subpath> fork one two
.> cd .

Now let's edit one of the terms...

someTerm : Optional x -> Optional x
someTerm _ = None

... in one of the namespaces...

.subpath.one> update.old

The other namespace should be left alone.

.subpath> view two.someTerm