Stream: beginners

Topic: Is this function allowed/possible in roc?


view this post on Zulip Nikolaus Wettstein (Jan 04 2023 at 14:41):

List [One, Two] -> List [One]

The function is only allowed to return One-Tags but it is returning a Two-Tag without any compiler errors: https://github.com/ni-ko-o-kin/advent-of-code-2022-roc/blob/e176fa9804d9ba598f8c4a55b2ca2adc258b0e83/OneTwo.roc#L24

view this post on Zulip Ayaz Hafiz (Jan 04 2023 at 15:02):

Ouch, yeah that's a bug. Could you please file an issue?

view this post on Zulip Nikolaus Wettstein (Jan 04 2023 at 15:10):

Sure!

view this post on Zulip Nikolaus Wettstein (Jan 04 2023 at 15:15):

But is this function possible in roc? Does the compiler know that I only returned One-Tags in all when-is branches? (regardless of the compiler bug)

view this post on Zulip Ayaz Hafiz (Jan 04 2023 at 15:25):

Well, that function is currently inferred as List [One, Two] -> List [One, Two] (the bug is that the output tag is allowed to grow larger than you specified)

view this post on Zulip Ayaz Hafiz (Jan 04 2023 at 15:25):

If both of your when branches were -> One then List [One, Two] -> List [One] would be inferred.


Last updated: Jul 05 2025 at 12:14 UTC