How to update code or upgrade a library dependency

The process of applying a potentially breaking change to your code need not be stressful. Here's how Unison handles that process in two common cases:

Updating your own code

Sometimes you'll need to make a change in the codebase that can't automatically be propagated to dependent functions, for example: if you alter a data constructor for a type or change the arguments to a function. Unison can programmatically guide you through the edits that you need to make in these cases.

Suggested workflow summary:

  1. enterupdatein the UCM to save your changes
  2. The UCM opens up non-typechecking code in your editor
  3. Fix the impacted terms and save the file
  4. runupdateto commit your changes.

Walk through an example

Let's say we have a simple type and a few functions which make use of that type in our codebase:

unique type Box = Box Nat

Box.toText : Box -> Text
Box.toText box = match box with
  Box.Box nat -> Nat.toText nat

Box.print : Box -> {IO,Exception} ()
Box.print box =
  Box.toText box |> printLine
myProject/main> add

We add it to the codebase but later, we may realize its data constructor should be changed.

myProject/main> edit Box
unique type Box = Box Int

We've changed the data constructor from taking a value of typeNattoInt.Upon saving the file and runningupdateagain, the UCM will open up the impacted terms in your editor.

myProject/main> update

Okay, I'm searching the branch for code that needs to be

That's done. Now I'm making sure everything typechecks...

Typechecking failed. I've updated your scratch file with the
definitions that need fixing. Once the file is compiling, try
`update` again.

All impacted terms, including indirect dependents, will be opened in your scratch file.

Box.print : Box ->{IO, Exception} ()
Box.print box = Box.toText box |> printLine

Box.toText : Box -> Text
Box.toText = cases Box nat -> Nat.toText nat

unique type Box = Box Int
The 1st argument to `Nat.toText`

        has type:  Int
  but I expected:  Nat

  5 | Box.toText = cases Box nat -> Nat.toText nat
  6 |
  7 | unique type Box = Box Int

The UCM will start printing typechecking errors to the console starting from the top of the file so you know what to tackle first. In our example, the functionBox.printis opened in the editor even though the change we need to make is in theBox.toTextfunction. That's because resolving larger, more complicated updates can involve propagating changes to many terms, all the way up the function call chain. With this workflow, you can be assured that your change will leave your codebase in a consistent state. Once all the errors are fixed, you can runupdateagain to commit your changes.

How to update a library dependency

Upgrading a library is very similar to the regular process of updating Unison code. It involves one additional simple command. The following workflow uses Unison's standard library,base,as an example.


Upgrade workflow:

    • pullthe latest version of the dependency into your codebase so that it is a sibling of your current library version.
      • myProject/main> pull @unison/base/releases/2.0.0 lib.base_2_0_0
    • Run theupgradecommand, indicating which library you'd like to upgrade
      • myProject/main> upgrade base_1_0_0 base_2_0_0
  1. If there are conflicts to resolve, the UCM will open up the affected terms in your editor. Resolve the conflicts and enterupdateagain once the file typechecks.

In rare cases, the Unison project that you're depending upon may be located in a user'spublicnamespace, and therefore predates the project ecosystem. In that case, you can usethis process for upgrading.