Stream: beginners

Topic: Don't allow direct imports


view this post on Zulip Martin Stewart (Nov 20 2021 at 16:03):

It looks Roc supports directly exposing functions and types? This for example import A exposing (functionA) and writing functionA directly vs import A and then needing to qualify the function call withA.functionA.

Assuming that is true, I want to make an argument for not supporting it. With Elm, elm-format spares us from having debates over code style. But when it comes to imports, some people want to directly expose everything from a particular module, other people want to only directly expose types, and often there's special cases for Test functions or Html. At work we lose time now and then debating this stuff but since Roc is going to have a purpose built editor, what if direct imports could be an editor configuration? Then everyone can have it their way without any conflict.

The .roc files themselves would have no direct imports but when someone opens it in their editor, directly imported functions and types would be shown without any qualifiers. And when the user writes one of those functions and saves, the editor will add qualifiers to the .roc file.

view this post on Zulip Anton (Nov 20 2021 at 16:32):

I believe if you want to import functionA from A, the syntax is imports [ A.functionA ].
For tools it might be useful to have the default be direct imports so they do not need to parse the whole file to know what is used, only the header.
I do like the idea.

view this post on Zulip Brendan Hansknecht (Nov 20 2021 at 16:43):

The editor idea is cool, but complex. Most likely people only want some direct imports and not all things to be direct imports.

view this post on Zulip Brendan Hansknecht (Nov 20 2021 at 16:47):

As for whether or not they should be supported. I would say an argument for not supporting them is that someone can do it manually if they really want it.

Import A

functionA = A.functionA

Also, most style guides i have seen for various languages definitely promote A.* Syntax because it removes ambiguity in a large code base.

view this post on Zulip Anton (Nov 20 2021 at 16:48):

 Most likely people only want some direct imports and not all things to be direct imports.

Uhu, I find myself doing the same.

view this post on Zulip Brendan Hansknecht (Nov 20 2021 at 16:49):

I am open to either option, but I understand only supporting one syntax. The big advantage of both is that it let's the user pick their style here. I think that is fine, but as said above, it can lead to debates when the rules aren't set in stone.


Last updated: Jul 06 2025 at 12:14 UTC