Are there some plans to evaluate inputs against functions to determine whether an error path could occur or not and eventually determine that there's no error in some cases?
Sample:
sample = List.min([1, 2, 3])?
Here you need to handle ListWasEmpty
at some point, even though this list should likely never be empty. That's a bit contrived but as a sample one could take something such as calculate_smallest_surface_area_of_rectangle
that is called within a function that always needs to receive a length, width and height.
We have plans for something like this to be evaluated at compile time and be reduced to a constant. In this case if we had something like List.min : List(Num(size)) -> Result(Num(size), [ListWasEmpty])
, this would probably just be equivalent to a constant Ok(1)
in memory.
That doesn't really answer your question which I think is aimed at runtime and specifically an optimisation to elide bounds checking or something like that?
Actually was looking more into it from design time / editor perspective in the sense of knowing the right things to take care of and avoiding noise on things the might never happen (well never say never :sweat_smile:).
Ah, make impossible things impossible!
You can use a Tuple or Record if you have a compile time fixed size.
Or wrap a list with some helpers NonEmptyList(a) := List(a)
etc
Here is a real world example of how to use NonEmptyList: https://github.com/roc-lang/basic-cli/blob/main/examples/terminal-app-snake.roc
A general solution to these type of issues is dependent types but that would also add significant complexity to the compiler.
Last updated: Jul 26 2025 at 12:14 UTC