Stream: beginners

Topic: Code Evaluation - Unreachable Errors at a later point?


view this post on Zulip Tobias Steckenborn (Jul 13 2025 at 10:43):

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.

view this post on Zulip Luke Boswell (Jul 13 2025 at 10:48):

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.

view this post on Zulip Luke Boswell (Jul 13 2025 at 10:49):

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?

view this post on Zulip Tobias Steckenborn (Jul 13 2025 at 10:50):

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:).

view this post on Zulip Luke Boswell (Jul 13 2025 at 10:51):

Ah, make impossible things impossible!

view this post on Zulip Luke Boswell (Jul 13 2025 at 10:52):

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

view this post on Zulip Anton (Jul 13 2025 at 12:45):

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

view this post on Zulip Anton (Jul 13 2025 at 12:46):

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