Stream: ideas

Topic: roc sub-command to annotate top-level values


view this post on Zulip Elias Mulhall (Dec 07 2023 at 23:06):

One of the selling points of Roc's type system is that if the code compiles then all types can be inferred without annotations. This means that you can write Roc code without having to worry about annotations, but it also means that given any valid Roc program we can generate and insert missing top-level annotations.

This idea has definitely come up before in the context of editor tooling. Editors should be able to display the inferred type of a function and optionally insert the type as an annotation.

Something I'm not sure has been talked about is the ability to bulk-add annotations for every top-level value in a file/directory. It could be like roc add-types main.roc.

Pros

Cons

view this post on Zulip Ryan Bates (Dec 07 2023 at 23:22):

This idea has definitely come up before in the context of editor tooling. Editors should be able to display the inferred type of a function and optionally insert the type as an annotation.

As a beginner who has only dabbled in annotated types in Roc, seeing the inferred type in the editor would be awesome. I assume it could be done on any value (if the code compiles).

Something I'm not sure has been talked about is the ability to bulk-add annotations for every top-level value in a file/directory. It could be like roc add-types main.roc.

I personally wouldn't use this. The inferred types get pretty messy when I am passing records and lists around. I'd rather annotate types myself with proper named aliases. If there's a code policy of always annotating types then auto-generating types can lead to types that are difficult to read and cumbersome to change.

Similar to formatting, having a blanket "always annotate top level values" policy helps to keep a project consistent

I'd rather have a linter to enforce this policy instead of generating it.

view this post on Zulip Elias Mulhall (Dec 08 2023 at 00:56):

Fair enough. For the editor tooling part we have a language server, I don't think it gives type sigs yet but I'm sure it will eventually.

view this post on Zulip Luke Boswell (Dec 08 2023 at 01:00):

It's working for me :hearts:
Screenshot-2023-12-08-at-12.00.06.png

view this post on Zulip Elias Mulhall (Dec 08 2023 at 01:02):

Oh nice, must be vim's fault :laughing:

view this post on Zulip Ayaz Hafiz (Dec 08 2023 at 01:08):

works for me on vim too

view this post on Zulip Ayaz Hafiz (Dec 08 2023 at 01:09):

Try restarting it, it can crash sometimes

view this post on Zulip Elias Mulhall (Dec 08 2023 at 01:10):

Nah let me rephrase -- it must be an issue with my personal bespoke vim setup.

view this post on Zulip Elias Mulhall (Dec 08 2023 at 01:11):

Inline error reporting is working, there's just a particular keybinding I expect to trigger that kind of hover info and I bet it's misconfigured

view this post on Zulip Artur Domurad (Dec 08 2023 at 08:28):

An action in IDE that generates the type of a specific function would be amazing :)

Maybe I'm lazy, but I do it all the time in elm - first autogenerate, and then change or tweak if necessary:
elm2.png
elm1.png

It is also a "WOW" factor for people new to the language - "it really can guess any type..." :grinning_face_with_smiling_eyes:

view this post on Zulip Johan Lindskogen (Dec 08 2023 at 08:41):

Artur Domurad said:

An action in IDE that generates the type of a specific function would be amazing :smile:

Maybe I'm lazy, but I do it all the time in elm - first autogenerate, and then change or tweak if necessary:
elm2.png
elm1.png

It is also a "WOW" factor for people new to the language - "it really can guess any type..." :grinning_face_with_smiling_eyes:

:+1: for this, it really is a godsend!

view this post on Zulip Artur Domurad (Dec 08 2023 at 09:45):

Hmm, but when I'm coding roc, most often I will just create type annotations for functions instead of implementations for the whole program. And when the whole program structure is ready and compiles then I'm starting to implement the missing implementations.
I think this might be the most "mind blowing" feature of roc for people new to the language.

So, maybe an "action" like "create a function header for this unrecognized identifier" would also be useful :D
Missing function:
infer1.png

Click, and ready (it compiles):
infer2.png

view this post on Zulip Luke Boswell (Dec 08 2023 at 21:50):

Artur Domurad said:

Hmm, but when I'm coding roc, most often I will just create type annotations for functions instead of implementations for the whole program. And when the whole program structure is ready and compiles then I'm starting to implement the missing implementations.
I think this might be the most "mind blowing" feature of roc for people new to the language.

Where would the best place be to introduce this feature and to describe this workflow for people? Like you you expect to see a paragraph in the tutorial on this? Or maybe a guide somewhere? It might be good to capture this somehow?

view this post on Zulip Artur Domurad (Dec 09 2023 at 11:56):

I'm just thinking out loud... Right now, probably everyone has their own way/flow when working with roc.
Sooner or later this things will probably appear in some roc IDE extensions/plugins.

By the way: Is the roc editor still planned?

view this post on Zulip Anton (Dec 10 2023 at 11:38):

By the way: Is the roc editor still planned?

Yes, but we unfortunately have plenty of higher priority issues for the moment.

view this post on Zulip Eli Dowling (Dec 12 2023 at 11:33):

Artur Domurad said:

So, maybe an "action" like "create a function header for this unrecognized identifier"

I love this idea, I'm not totally sure how easy it would be, but I can have a play around with the lang server and give you an estimate on whetherI think it's a "sure, could get it happening in an afternoon" or a "well if we rearchitect the compiler...." Or somewhere in between :)


Last updated: Jun 16 2026 at 16:19 UTC