2019-11-14 00:57:51 +03:00
|
|
|
# Suffix-based resolution of names
|
|
|
|
|
|
|
|
Any unique name suffix can be used to refer to a definition. For instance:
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
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
|
|
|
|
```
|
|
|
|
|
2020-03-19 21:30:30 +03:00
|
|
|
This also affects commands like find. Notice lack of qualified names in output:
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2019-11-14 00:57:51 +03:00
|
|
|
|
2020-03-19 21:30:30 +03:00
|
|
|
⍟ I've added these definitions:
|
2020-02-25 02:40:54 +03:00
|
|
|
|
2020-03-19 21:30:30 +03:00
|
|
|
foo.bar.a : Int
|
|
|
|
optional.isNone : Optional a -> Boolean
|
2019-11-14 00:57:51 +03:00
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> find take
|
2019-11-14 00:57:51 +03:00
|
|
|
|
|
|
|
1. builtin.Bytes.take : Nat -> Bytes -> Bytes
|
|
|
|
2. builtin.List.take : Nat -> [a] -> [a]
|
|
|
|
3. builtin.Text.take : Nat -> Text -> Text
|
2021-02-02 01:10:22 +03:00
|
|
|
4. builtin.io2.MVar.take.impl : MVar a ->{IO} Either Failure a
|
2020-09-03 22:40:50 +03:00
|
|
|
5. builtin.io2.MVar.tryTake : MVar a ->{IO} Optional a
|
2020-02-25 02:40:54 +03:00
|
|
|
|
2019-11-14 00:57:51 +03:00
|
|
|
|
2020-03-19 21:18:56 +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
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view List.drop
|
2020-03-19 21:18:56 +03:00
|
|
|
|
2021-09-28 00:25:23 +03:00
|
|
|
builtin builtin.List.drop : builtin.Nat -> [a] -> [a]
|
2020-03-19 21:18:56 +03:00
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> display bar.a
|
2020-03-19 21:30:30 +03:00
|
|
|
|
|
|
|
+99
|
|
|
|
|
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`:
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> find : Nat -> [a] -> [a]
|
2019-11-14 00:57:51 +03:00
|
|
|
|
|
|
|
1. builtin.List.drop : Nat -> [a] -> [a]
|
|
|
|
2. builtin.List.take : Nat -> [a] -> [a]
|
2020-02-25 02:40:54 +03:00
|
|
|
|
2019-11-14 00:57:51 +03:00
|
|
|
|
2022-04-07 08:42:59 +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
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-04-07 08:42:59 +03:00
|
|
|
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"
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-04-07 08:42:59 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-04-07 08:42:59 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
|
|
|
cool.abra.cadabra : Text
|
|
|
|
lib.distributed.abra.cadabra : Text
|
|
|
|
lib.distributed.baz.qux : Text
|
|
|
|
lib.distributed.lib.baz.qux : Text
|
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2022-04-07 08:42:59 +03:00
|
|
|
|
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
cool.abra.cadabra : Text
|
|
|
|
lib.distributed.abra.cadabra : Text
|
|
|
|
lib.distributed.baz.qux : Text
|
|
|
|
lib.distributed.lib.baz.qux : Text
|
|
|
|
|
2024-03-19 19:56:03 +03:00
|
|
|
```
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2024-03-19 19:56:03 +03:00
|
|
|
> abra.cadabra
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-03-19 19:56:03 +03:00
|
|
|
|
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
|
|
|
I couldn't figure out what abra.cadabra refers to here:
|
|
|
|
|
|
|
|
1 | > abra.cadabra
|
|
|
|
|
|
|
|
The name abra.cadabra is ambiguous. I couldn't narrow it down
|
|
|
|
by type, as any type would work here.
|
|
|
|
|
|
|
|
I found some terms in scope that have matching names and
|
|
|
|
types. Maybe you meant one of these:
|
|
|
|
|
|
|
|
cool.abra.cadabra : Text
|
|
|
|
distributed.abra.cadabra : Text
|
|
|
|
|
2024-03-19 21:48:27 +03:00
|
|
|
```
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2024-03-19 21:48:27 +03:00
|
|
|
> baz.qux
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-03-19 21:48:27 +03:00
|
|
|
|
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
|
|
|
✅
|
|
|
|
|
|
|
|
scratch.u changed.
|
|
|
|
|
|
|
|
Now evaluating any watch expressions (lines starting with
|
|
|
|
`>`)... Ctrl+C cancels.
|
|
|
|
|
|
|
|
1 | > baz.qux
|
|
|
|
⧩
|
|
|
|
"direct dependency 2"
|
|
|
|
|
2022-04-07 08:42:59 +03:00
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view abra.cadabra
|
2022-04-07 08:42:59 +03:00
|
|
|
|
|
|
|
cool.abra.cadabra : Text
|
|
|
|
cool.abra.cadabra = "my project"
|
2024-03-19 19:56:03 +03:00
|
|
|
|
|
|
|
lib.distributed.abra.cadabra : Text
|
|
|
|
lib.distributed.abra.cadabra = "direct dependency 1"
|
2022-04-07 08:42:59 +03:00
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view baz.qux
|
2022-04-07 08:42:59 +03:00
|
|
|
|
|
|
|
lib.distributed.baz.qux : Text
|
|
|
|
lib.distributed.baz.qux = "direct dependency 2"
|
|
|
|
|
|
|
|
```
|
|
|
|
Note that we can always still view indirect dependencies by using more name segments:
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view distributed.abra.cadabra
|
2022-04-07 08:42:59 +03:00
|
|
|
|
|
|
|
lib.distributed.abra.cadabra : Text
|
|
|
|
lib.distributed.abra.cadabra = "direct dependency 1"
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> names distributed.lib.baz.qux
|
2022-04-07 08:42:59 +03:00
|
|
|
|
|
|
|
Term
|
|
|
|
Hash: #nhup096n2s
|
|
|
|
Names: lib.distributed.lib.baz.qux
|
|
|
|
|
2019-11-14 00:57:51 +03:00
|
|
|
```
|