unison/unison-src/transcripts/propagate.md
2024-07-01 14:29:32 -07:00

1.3 KiB

Propagating type edits

scratch/main> builtins.merge lib.builtins

We introduce a type Foo with a function dependent fooToInt.

unique type Foo = Foo

fooToInt : Foo -> Int
fooToInt _ = +42

And then we add it.

scratch/main> add
scratch/main> find.verbose
scratch/main> view fooToInt

Then if we change the type Foo...

unique type Foo = Foo | Bar

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

scratch/main> update.old

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

scratch/main> 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.

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:

scratch/main> add

Let's now edit the dependency:

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

Update...

scratch/main> update.old

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

scratch/main> view preserve.someTerm
scratch/main> view preserve.otherTerm