Stream: ideas

Topic: main.roc


view this post on Zulip Richard Feldman (Jun 14 2022 at 17:48):

just came up with a nice ergonomics improvement for the Roc CLI:
https://github.com/rtfeldman/roc/issues/3222

view this post on Zulip Brendan Hansknecht (Jun 14 2022 at 21:27):

Any reason for "root" and not "main" or similar? Just trying to think if there are other more common naming conventions that might be more proper to use.

view this post on Zulip Brendan Hansknecht (Jun 14 2022 at 21:27):

Side, note, would it be possible to just grab this information from the Package-Config.roc and instead start there?

view this post on Zulip Richard Feldman (Jun 14 2022 at 23:05):

ooh I like main!

view this post on Zulip Richard Feldman (Jun 14 2022 at 23:06):

the terminology I've been using in my head for the [app/platform/package] module is "the root module of your project" because it imports all the other modules, so it's at the root of the dependency tree

view this post on Zulip Richard Feldman (Jun 14 2022 at 23:06):

but main.roc seems like a much better fit for app modules, and seems fine for packages and platforms too :thumbs_up:

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:06):

isn't this what -- is for. So I can cargo run -- arg for the app vs cargo run args for cargo

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:06):

no need to add an extra flag for that

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:06):

also packages don't have a root right?

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:28):

packages need a root package module just like apps have an app module and platforms have a platform module - to specify things like "here are the packages I depend on, here are the modules that I want to publicly expose" etc

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:29):

I thought about -- but it seems like that would make the typical case less convenient in order to make the rare case more convenient, whereas --root (or --main) would make the typical case more convenient and the rare case less convenient

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:30):

-- is pretty standard though?

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:32):

sure, which is why I'd go for it if it were the most convenient, but I think we can do better than the standard! :smiley:

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:36):

well going "against the standard" is in itself confusing. And in designing the language you want to "spend the weirdness budget" somewhere to bring something new to the table. But when it comes to how cli arguments are parsed I think the tradeoff is different

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:36):

also how would you pass flags to the compiler, like what target or linker to use? it's order-dependent ?

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:39):

E.g. here how do I distinguish arguments for the application vs for the compiler?

roc run --main=Foo.roc --linker=legacy arg1 arg2

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:39):

oh I see

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:39):

versus

roc run Foo.roc --linker=legacy -- arg1 arg2

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:40):

like if you want to pass an argument to the application that happens to have the same name as an argument the compiler CLI accepts

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:40):

including a flag

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:40):

interesting

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:40):

this is exactly what -- solves: it kind of does "scoping" of the arguments

view this post on Zulip Richard Feldman (Jun 15 2022 at 12:41):

so cargo run makes -- optional - should we make it required, just to be explicit about that?

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:42):

right, cargo run --help is ambiguous, for instance

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:43):

we should pick whatever can give the best error messages here when it fails. I'm not sure which that is

view this post on Zulip Folkert de Vries (Jun 15 2022 at 12:44):

making it required is probably a good default that you can later relax

view this post on Zulip Richard Feldman (Jun 15 2022 at 13:00):

makes sense! I updated the issue

view this post on Zulip Richard Feldman (Jun 15 2022 at 13:21):

:thinking: maybe we should do both?

view this post on Zulip Richard Feldman (Jun 15 2022 at 13:22):

I could see it being confusing if I did roc run datafile.json and got an error about how datafile.json is not valid Roc source code

view this post on Zulip Qqwy / Marten (Jun 15 2022 at 13:45):

On top of what @Folkert de Vries already mentioned: What if you build a Roc program that itself wants to use the --main (or insert whatever flag roc also supports) flag?
Usage of -- is a clear way to scope the arguments. The other alternative that I've seen in some places is to wrap all (or any potentially conflicting) arguments in an extra layer of nesting, say --app-arg="--main" which becomes very tedious very quickly (for instance needing to doubly escape strings)

view this post on Zulip Richard Feldman (Jun 15 2022 at 13:47):

yeah I'm sold on --


Last updated: Jun 16 2026 at 16:19 UTC