unison/unison-src/transcripts/suffixes.md

76 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

# Suffix-based resolution of names
```ucm:hide
scratch/main> builtins.merge
```
Any unique name suffix can be used to refer to a definition. For instance:
2020-03-19 21:30:30 +03:00
```unison:hide
-- No imports needed even though FQN is `builtin.{Int,Nat}`
foo.bar.a : Int
foo.bar.a = +99
-- No imports needed even though FQN is `builtin.Optional.{None,Some}`
optional.isNone = cases
None -> true
Some _ -> false
```
This also affects commands like find. Notice lack of qualified names in output:
```ucm
scratch/main> add
scratch/main> find take
```
2020-03-19 21:30:30 +03:00
The `view` and `display` commands also benefit from this:
2020-03-19 21:18:56 +03:00
```ucm
scratch/main> view List.drop
scratch/main> display bar.a
2020-03-19 21:18:56 +03:00
```
In the signature, we don't see `base.Nat`, just `Nat`. The full declaration name is still shown for each search result though.
Type-based search also benefits from this, we can just say `Nat` rather than `.base.Nat`:
```ucm
scratch/main> find : Nat -> [a] -> [a]
```
2024-03-19 19:56:03 +03:00
## Preferring names not in `lib.*.lib.*`
2022-04-07 08:42:59 +03:00
2024-03-19 19:56:03 +03:00
Suffix-based resolution prefers names that are not in an indirect dependency.
2022-04-07 08:42:59 +03:00
```unison
cool.abra.cadabra = "my project"
lib.distributed.abra.cadabra = "direct dependency 1"
lib.distributed.baz.qux = "direct dependency 2"
lib.distributed.lib.baz.qux = "indirect dependency"
```
```ucm
scratch/main> add
2022-04-07 08:42:59 +03:00
```
2024-03-19 19:56:03 +03:00
```unison:error
2022-04-07 08:42:59 +03:00
> abra.cadabra
2024-03-19 19:56:03 +03:00
```
```unison
2022-04-07 08:42:59 +03:00
> baz.qux
```
```ucm
scratch/main> view abra.cadabra
scratch/main> view baz.qux
2022-04-07 08:42:59 +03:00
```
Note that we can always still view indirect dependencies by using more name segments:
```ucm
scratch/main> view distributed.abra.cadabra
scratch/main> names distributed.lib.baz.qux
2022-04-07 08:42:59 +03:00
```