Stream: ideas

Topic: Anonymous Annotation


view this post on Zulip Luke Boswell (Oct 16 2023 at 10:08):

This almost certainly a wacky idea, but thought I would share it anyway.

I was looking at code similar to the below and had a thought; I wondered if you should be able to add a type annotation when deconstructing values... maybe it would make sense to have an anonymous annotation like below?

expect

    first : { foo : U32 }                # annotation for ident `first`
    first = { foo: 12 }

    : {bar : U32, baz : Dec }            # annotation for anonymous struct?
    {bar, baz} = {bar: 24, baz: 36.0 }

    first.foo == 12 && bar == 24 && baz == 36.0

It looks a bit strange, and you could just assign it to an identifier if you wanted an annotation. But I guess this could reduce visual clutter without the additional identifier.

view this post on Zulip Anton (Oct 16 2023 at 10:21):

Interesting, although I wonder if it would still be valuable once you have "type on hover" support in an editor.

view this post on Zulip Luke Boswell (Oct 16 2023 at 10:27):

I was thinking the primary benefit for an annotation is to help the compiler help you, so if the types are not what is expected then you get a more accurate error.

view this post on Zulip Luke Boswell (Oct 16 2023 at 10:29):

Type on hover sounds great though

view this post on Zulip Hannes (Oct 16 2023 at 12:29):

You can already do this, right? I checked and you can't

bar : U32
baz : Dec
{ bar, baz } = { bar: 24, baz: 36.0 }

Or can type hints only go on the line directly before something is defined?
If you can do that, it might make sense to be able to put those type hints on one line somehow, like this?

bar : U32, baz : Dec
{ bar, baz } = { bar: 24, baz: 36.0 }

view this post on Zulip Hannes (Oct 16 2023 at 12:33):

Or even this:

{ bar, baz } : { bar : U32, baz : Dec }
{ bar, baz } = { bar: 24, baz: 36.0 }

view this post on Zulip Hannes (Oct 16 2023 at 12:33):

I'm surprised that last one doesn't work already, I just assumed it would :shrug:

view this post on Zulip Luke Boswell (Oct 16 2023 at 18:10):

That last one looks nice I think. Hadn't thought of that.


Last updated: Jun 16 2026 at 16:19 UTC