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
name = "foo" as a top-level, and not really want the name : Str annotation.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.
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.
It's working for me :hearts:
Screenshot-2023-12-08-at-12.00.06.png
Oh nice, must be vim's fault :laughing:
works for me on vim too
Try restarting it, it can crash sometimes
Nah let me rephrase -- it must be an issue with my personal bespoke vim setup.
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
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:
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.pngIt 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!
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
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 ofrocfor 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?
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?
By the way: Is the roc editor still planned?
Yes, but we unfortunately have plenty of higher priority issues for the moment.
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