2022-12-02 08:24:58 +03:00
|
|
|
This transcript demonstrates that Unison forces actions in blocks to have a return type of `()`.
|
|
|
|
|
|
|
|
This works, as expected:
|
|
|
|
|
|
|
|
```unison
|
|
|
|
structural ability Stream a where emit : a -> ()
|
|
|
|
|
|
|
|
ex1 = do
|
|
|
|
Stream.emit 1
|
|
|
|
Stream.emit 2
|
|
|
|
42
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
|
|
|
|
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`:
|
|
|
|
|
|
|
|
structural ability Stream a
|
|
|
|
ex1 : '{Stream Nat} Nat
|
|
|
|
|
|
|
|
```
|
|
|
|
This does not typecheck, we've accidentally underapplied `Stream.emit`:
|
|
|
|
|
|
|
|
```unison
|
|
|
|
ex2 = do
|
|
|
|
Stream.emit
|
|
|
|
42
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
|
2022-12-02 22:50:20 +03:00
|
|
|
I found a value of type: a ->{Stream a} Unit
|
2022-12-02 08:24:58 +03:00
|
|
|
where I expected to find: Unit
|
|
|
|
|
|
|
|
2 | Stream.emit
|
2022-12-02 22:50:20 +03:00
|
|
|
|
|
|
|
Note: actions within a block must have type Unit.
|
2022-12-02 08:24:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
We can explicitly ignore an unused result like so:
|
|
|
|
|
|
|
|
```unison
|
|
|
|
ex3 = do
|
|
|
|
_ = Stream.emit
|
|
|
|
()
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
|
|
|
|
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`:
|
|
|
|
|
|
|
|
ex3 : '()
|
|
|
|
|
|
|
|
```
|
|
|
|
Using a helper function like `void` also works fine:
|
|
|
|
|
|
|
|
```unison
|
|
|
|
void x = ()
|
|
|
|
|
|
|
|
ex4 =
|
|
|
|
void [1,2,3]
|
|
|
|
()
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
|
|
|
|
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`:
|
|
|
|
|
|
|
|
ex4 : ()
|
|
|
|
void : x -> ()
|
|
|
|
|
|
|
|
```
|
|
|
|
One more example:
|
|
|
|
|
|
|
|
```unison
|
|
|
|
ex4 =
|
|
|
|
[1,2,3] -- no good
|
|
|
|
()
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
|
2022-12-02 22:50:20 +03:00
|
|
|
I found a value of type: [Nat]
|
2022-12-02 08:24:58 +03:00
|
|
|
where I expected to find: Unit
|
|
|
|
|
|
|
|
2 | [1,2,3] -- no good
|
|
|
|
|
|
|
|
from right here:
|
|
|
|
|
|
|
|
2 | [1,2,3] -- no good
|
|
|
|
|
2022-12-02 22:50:20 +03:00
|
|
|
Note: actions within a block must have type Unit.
|
|
|
|
|
2022-12-02 08:24:58 +03:00
|
|
|
|
|
|
|
```
|