mirror of
https://github.com/unisonweb/unison.git
synced 2024-10-26 11:07:48 +03:00
1.7 KiB
1.7 KiB
This transcript demonstrates that Unison forces actions in blocks to have a return type of ()
.
This works, as expected:
structural ability Stream a where emit : a -> ()
ex1 = do
Stream.emit 1
Stream.emit 2
42
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
:
ex2 = do
Stream.emit
42
I found a value of type: a ->{Stream a} Unit
where I expected to find: Unit
2 | Stream.emit
Note: actions within a block must have type Unit.
We can explicitly ignore an unused result like so:
ex3 = do
_ = Stream.emit
()
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:
void x = ()
ex4 =
void [1,2,3]
()
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:
ex4 =
[1,2,3] -- no good
()
I found a value of type: [Nat]
where I expected to find: Unit
2 | [1,2,3] -- no good
from right here:
2 | [1,2,3] -- no good
Note: actions within a block must have type Unit.