2019-11-14 00:57:51 +03:00
|
|
|
# Suffix-based resolution of names
|
|
|
|
|
2020-02-13 18:59:53 +03:00
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> builtins.merge
|
2020-02-13 18:59:53 +03:00
|
|
|
```
|
|
|
|
|
2019-11-14 00:57:51 +03:00
|
|
|
Any unique name suffix can be used to refer to a definition. For instance:
|
|
|
|
|
2020-03-19 21:30:30 +03:00
|
|
|
```unison:hide
|
2019-11-14 00:57:51 +03:00
|
|
|
-- 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}`
|
2020-02-22 02:48:12 +03:00
|
|
|
optional.isNone = cases
|
2019-11-14 00:57:51 +03:00
|
|
|
None -> true
|
|
|
|
Some _ -> false
|
|
|
|
```
|
|
|
|
|
|
|
|
This also affects commands like find. Notice lack of qualified names in output:
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
|
|
|
scratch/main> find take
|
2019-11-14 00:57:51 +03:00
|
|
|
```
|
|
|
|
|
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
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view List.drop
|
|
|
|
scratch/main> display bar.a
|
2020-03-19 21:18:56 +03:00
|
|
|
```
|
|
|
|
|
2019-11-14 00:57:51 +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
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> find : Nat -> [a] -> [a]
|
2019-11-14 00:57:51 +03:00
|
|
|
```
|
2021-08-04 21:26:13 +03:00
|
|
|
|
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
|
2024-06-12 01:22:09 +03:00
|
|
|
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
|
2024-06-12 01:22:09 +03:00
|
|
|
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
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view distributed.abra.cadabra
|
|
|
|
scratch/main> names distributed.lib.baz.qux
|
2022-04-07 08:42:59 +03:00
|
|
|
```
|