Does module params + comp time = conditional compilation?
This is a thought I have had in the back of my mind for a while. With the suggested module params and compilation time evaluation features, I wonder if it is possible to enable a form of conditional compilation for API design? (Possibly some other changes to the compiler are necessary, as I am not sure comp time enables the example below.)
Here is an example. Imagine there is a module that defines some sorting function for lists, but where it can choose which implementation to export based on a setting parameter that is passed to the module.
Sorting.roc:
module { setting} -> [sort]
sort =
when setting is
ShortList -> sortShortList
LongList -> sortLongList
sortShortList = #implementation optimized for short lists
sortLongList = #implementation optimized for long lists
Then I could import and use this module in my code as
setting = ShortList
import Sorting {setting}
sortedList = lst |> Sorting.sort
With the optimized version for my case, without needing to check the when-is condition on each call of Sorting.sort.
potentially! We have an open question for what module params should compile to
if they compile to adding a hidden extra param to all the module's top-level declarations, then whether or not this would be free at runtime would depend on whether inlining happened (which would be based on a heuristic)
we need to at a minimum support this way of compiling module params, because it's the only way to do it when modules are imported in the middle of functions
but there's a separate question of whether we should also support additional compilation strategies for top-level imports
or for imports that are "effectively top-level" (as in, they are written inline but they only depend on top-level values)
Great, thanks. All good considerations to keep in mind
Last updated: Jun 16 2026 at 16:19 UTC