Stream: beginners

Topic: Simple result with I/O


view this post on Zulip Mark J. Reed (Jun 20 2025 at 18:16):

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...

view this post on Zulip Anton (Jun 20 2025 at 18:22):

Hi @Mark J. Reed,
Stdout.write! returns Ok({}) on success, so in your other branch you'll have to end with Ok({}) as well.

view this post on Zulip Anton (Jun 20 2025 at 18:22):

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))

view this post on Zulip Mark J. Reed (Jun 20 2025 at 18:30):

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!```

view this post on Zulip Richard Feldman (Jun 20 2025 at 19:14):

it's a capitalization issue - should be Ok over OK :smiley:

view this post on Zulip Richard Feldman (Jun 20 2025 at 19:15):

that might be a good special-case compiler error to include

view this post on Zulip Kilian Vounckx (Jun 20 2025 at 21:13):

Might not even need to be special case?
Couldn't we check for tags which should be valid with different casing in general?

view this post on Zulip Richard Feldman (Jun 20 2025 at 22:11):

yeah we could do that after unrolling the type alias :thumbs_up:

view this post on Zulip Mark J. Reed (Jun 20 2025 at 22:15):

Ack! You'd think after 40 years of programming I'd be better at spotting a case issue. That's just embarrassing.

view this post on Zulip Richard Feldman (Jun 21 2025 at 00:45):

in fairness, OK is the usual way it's spelled; nobody really spells it Ok except for programming languages :stuck_out_tongue:

view this post on Zulip Anton (Jun 21 2025 at 08:08):

There is an issue for better error messages for OK #6630


Last updated: Jul 06 2025 at 12:14 UTC