unison/unison-src/transcripts/fix614.output.md
Greg Pfeil 0031542faf
Add a space before code block info strings
This is for consistency with the `cmark` style. Now the blocks we still
pretty-print ourselves will match the bulk of them that `cmark`
produces.
2024-07-10 13:56:07 -06:00

121 lines
2.0 KiB
Markdown

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
Loading changes detected in scratch.u.
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
Loading changes detected in scratch.u.
I found a value of type: a ->{Stream a} Unit
where I expected to find: Unit
2 | Stream.emit
3 | 42
Hint: Actions within a block must have type Unit.
Use _ = <expr> to ignore a result.
```
We can explicitly ignore an unused result like so:
``` unison
ex3 = do
_ = Stream.emit
()
```
``` ucm
Loading changes detected in scratch.u.
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
Loading changes detected in scratch.u.
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
Loading changes detected in scratch.u.
I found a value of type: [Nat]
where I expected to find: Unit
2 | [1,2,3] -- no good
3 | ()
from right here:
2 | [1,2,3] -- no good
Hint: Actions within a block must have type Unit.
Use _ = <expr> to ignore a result.
```