Stream: ideas

Topic: Enable optional module params


view this post on Zulip Johan Lövgren (Jan 03 2024 at 18:34):

(See discussion of module params & APIs for more context.)
A thought: could modules have optional parameters? Then one might declare a module as

Unicode: {language ? EnGb} -> [capitalize]

And then when importing it one could either choose to not pass in a parameter and use the default configuration, or one could pass it in and make an explicit choice. Would enable easy use of default configs.

view this post on Zulip Anton (Jan 03 2024 at 18:42):

Seems reasonable :)

view this post on Zulip Agus Zubiaga (Jan 03 2024 at 19:06):

This seems doable. I still have quite a few things to do before I can start implementing params, but my plan was to parse the params in the header as a regular record pattern.
So we might get this for free, at least the parsing of it.

view this post on Zulip Johan Lövgren (Jan 03 2024 at 19:12):

Cool!

view this post on Zulip Agus Zubiaga (Jun 27 2024 at 19:44):

If all module params are optional, should we require at least an empty record like we do for functions?

import Unicode {}

Or can the module be imported as if it had no params?

view this post on Zulip Agus Zubiaga (Jun 27 2024 at 19:49):

Requiring the record makes it more of an explicit "using the defaults" choice, but it means that adding params later would be a breaking change even if they were all optional

view this post on Zulip Sam Mohr (Jun 27 2024 at 20:03):

I would vote for the empty {}, it means it works the same way as function calls with all optional record fields

view this post on Zulip Sam Mohr (Jun 27 2024 at 20:07):

In the same way that ? and ! will work the same way, it would be nice to have language features that "work like you expect" because we have generally consistent rules

view this post on Zulip Agus Zubiaga (Jun 27 2024 at 20:55):

Yeah, that's what I'm leaning towards too

view this post on Zulip Johan Lövgren (Jun 28 2024 at 05:14):

I can see arguments for both, but I also like the consistency of including the empty {}. In my mind I think of modules with parameters as functions of the parameters, hence we are "calling the function" when we perform the import. In contrast to modules without parameters, which are more like constants.


Last updated: Jun 16 2026 at 16:19 UTC