How do I write the value that Stdout.write!
and friends return on success? I want my own routine to return a compatible value in both branches of a conditional, one of which does some output while the other does not...
Hi @Mark J. Reed,
Stdout.write!
returns Ok({})
on success, so in your other branch you'll have to end with Ok({})
as well.
You can figure this out like this btw:
main! : List Arg => Result {} _
main! = |_args|
res = Stdout.line!("Hello, World!")
Stdout.line!(Inspect.to_str(res))
Huh. I tried that, and got this:
This OK tag application has the type:
[OK {}]
but the then branch has the type:
Result {} [StdoutErr [
AlreadyExists,
BrokenPipe,
Interrupted,
NotFound,
Other Str,
OutOfMemory,
PermissionDenied,
Unsupported,
]]
All branches in an if must have the same type!```
it's a capitalization issue - should be Ok
over OK
:smiley:
that might be a good special-case compiler error to include
Might not even need to be special case?
Couldn't we check for tags which should be valid with different casing in general?
yeah we could do that after unrolling the type alias :thumbs_up:
Ack! You'd think after 40 years of programming I'd be better at spotting a case issue. That's just embarrassing.
in fairness, OK is the usual way it's spelled; nobody really spells it Ok except for programming languages :stuck_out_tongue:
There is an issue for better error messages for OK
#6630
Last updated: Jul 06 2025 at 12:14 UTC