unison/unison-src/transcripts/delete.md

2.6 KiB

Delete

.> builtins.merge

The delete command can delete both terms and types.

First, let's make sure it complains when we try to delete a name that doesn't exist.

.> delete.verbose foo

Now for some easy cases. Deleting an unambiguous term, then deleting an unambiguous type.

foo = 1
structural type Foo = Foo ()
.> add
.> delete.verbose foo
.> delete.verbose Foo
.> delete.verbose Foo.Foo

How about an ambiguous term?

foo = 1
.a> add
foo = 2
.b> add
.a> merge .b

A delete should remove both versions of the term.

.a> delete.verbose foo
.a> ls

Let's repeat all that on a type, for completeness.

structural type Foo = Foo ()
.a> add
structural type Foo = Foo
.b> add
.a> merge .b
.a> delete.verbose Foo
.a> delete.verbose Foo.Foo

Finally, let's try to delete a term and a type with the same name.

foo = 1
structural type foo = Foo ()
.> add
.> delete.verbose foo

We want to be able to delete multiple terms at once

a = "a"
b = "b"
c = "c"
.> add
.> delete.verbose a b c

We can delete terms and types in the same invocation of delete

structural type Foo = Foo ()
a = "a"
b = "b"
c = "c"
.> add
.> delete.verbose a b c Foo
.> delete.verbose Foo.Foo

We can delete a type and its constructors

structural type Foo = Foo ()
.> add
.> delete.verbose Foo Foo.Foo

You should not be able to delete terms which are referenced by other terms

a = 1
b = 2
c = 3
d = a + b + c
.> add
.> delete.verbose a b c

But you should be able to delete all terms which reference each other in a single command

e = 11
f = 12 + e
g = 13 + f
h = e + f + g
.> add
.> delete.verbose e f g h

You should be able to delete a type and all the functions that reference it in a single command

structural type Foo = Foo Nat

incrementFoo : Foo -> Nat
incrementFoo = cases
  (Foo n) -> n + 1
.> add
.> delete.verbose Foo Foo.Foo incrementFoo

If you mess up on one of the names of your command, delete short circuits

e = 11
f = 12 + e
g = 13 + f
h = e + f + g
.> add
.> delete.verbose e f gg

Cyclical terms which are guarded by a lambda are allowed to be deleted

ping _ = 1 Nat.+ !pong
pong _ = 4 Nat.+ !ping
.> add
.> delete.verbose ping
.> view pong