Stream: beginners

Topic: Provides Syntax


view this post on Zulip Zeljko Nesic (Apr 24 2021 at 21:50):

I am trying to understand what is this doing:

app "main" imports [ Effect ] provides [ rocMain ] to "./platform"

I mean this provides ... to ..... syntax, not sure what changes in platfrom

view this post on Zulip Folkert de Vries (Apr 24 2021 at 21:51):

the compiler needs to know what the main function is, and what the platform is that you want to compile

view this post on Zulip Zeljko Nesic (Apr 24 2021 at 21:52):

Ah, so no main as default?

view this post on Zulip Chad Stearns (Apr 24 2021 at 21:53):

Oh interesting, and its a list? So could it be [ mainA, mainB ]?

view this post on Zulip Folkert de Vries (Apr 24 2021 at 21:53):

right. This might be something to reconsider now. Originally, the idea was that you could hand multiple things to the platform (e.g. provide a update, a view, ect as separate functions)

view this post on Zulip Folkert de Vries (Apr 24 2021 at 21:54):

but we've confirmed that bundling all those functions in a record has no overhead; LLVM completely optimizes the struct/record away

view this post on Zulip Zeljko Nesic (Apr 24 2021 at 21:54):

 cat examples/balance/Main.roc
app "main" imports [ Effect ] provides [ rocMain, roKMain ] to "./platform"


rocMain : Effect.Effect {} as Fx
rocMain = ..

roKMain : Effect.Effect {} as Fx
roKMain = ..

THis is invalid syntax right?

There can be only one?!
:D

view this post on Zulip Folkert de Vries (Apr 24 2021 at 21:55):

well no, a platform could decide to allow this

view this post on Zulip Folkert de Vries (Apr 24 2021 at 21:55):

e.g. provides [ serverMain, clientMain ]

view this post on Zulip Chad Stearns (Apr 24 2021 at 21:55):

So, in theory, there could be a Roc mono repo, with the frontend and backend code base, like:

provides [ view, update, dbConnection, http ]

?

view this post on Zulip Zeljko Nesic (Apr 24 2021 at 21:55):

that should be a record then?

view this post on Zulip Folkert de Vries (Apr 24 2021 at 21:56):

yea I think that is generally preferable

view this post on Zulip Folkert de Vries (Apr 24 2021 at 21:56):

because then you have better docs for what the platform needs

view this post on Zulip Zeljko Nesic (Apr 24 2021 at 21:56):

provides { view, update: mainUpdateFix2 } to "xy"

view this post on Zulip Zeljko Nesic (Apr 24 2021 at 21:58):

but that is would be then equal to defaulting to only one main, where platform provides a spec what kind of data type it should be?


Last updated: Jul 05 2025 at 12:14 UTC