Stream: beginners

Topic: No `.to` or `.until` for number types besides U8


view this post on Zulip Ian McLerran (Dec 26 2025 at 04:18):

Hey all, just trying to figure out how to create a range List of type U64. It seems List.range() has been deprecated in favor of Num.to / Num.until, however it seems that currently, .to and .until are only implemented for U8. Is this by design (IE only desired for chars), or just not yet implemented?

I'd be happy to put together a PR to add for the other Integer(?) types if this is a desired addition...

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 04:43):

Definitely a bug

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 04:43):

Should work for any number type

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 04:43):

Or at least any integer type.... But I would argue any number type

view this post on Zulip Ian McLerran (Dec 26 2025 at 04:44):

Looking at Builtins.roc, it looks like it's only defined for U8 right now...

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 05:05):

Probably should just be a generic function and then called by each number type

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 05:06):

Probably was only added to u8 cause that was requested for AOC

view this post on Zulip Ian McLerran (Dec 26 2025 at 05:28):

Something like this?

# # List of integers beginning with this `I128` and ending with the other `I128`.
# # (Use [until] instead to end with the other `I128` minus one.)
# # Returns an empty list if this `I128` is greater than the other.
to : I128, I128 -> List(I128)
to = |start, end| range_to(start, end)

# # List of integers beginning with this `I128` and ending with the other `I128` minus one.
# # (Use [to] instead to end with the other `I128` exactly, instead of minus one.)
# # Returns an empty list if this `I128` is greater than or equal to the other.
until : I128, I128 -> List(I128)
until = |start, end| range_until(start, end)

Or is there a way to do a generic to and until function such that they don't need this stub definition for each type?

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 06:25):

Yeah, like that

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 06:25):

I think all need the stub

view this post on Zulip Richard Feldman (Dec 26 2025 at 13:35):

I'll just add this, no prob!

view this post on Zulip Ian McLerran (Dec 26 2025 at 14:50):

I've got it added for all the Int types on my local copy, but was curious if we for sure wanted it for dec/float types too, also needed to check if there is anywhere that Builtins are tested and add any appropriate tests

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 15:59):

I think Dec definitely should support it. It is as much an int as the integer types. It just happens to have a static scale. But it would function well with these functions. Float......maybe not....it has more risk of accidentally running into infinite loops.

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 16:00):

Also, what is our plan for ranges with different step sizes?

view this post on Zulip Brendan Hansknecht (Dec 26 2025 at 16:01):

Or with negative steps?

view this post on Zulip nandi (Dec 26 2025 at 17:55):

what if we had a range type? I like how julia does ranges like <initial>:<step>:<final> e.g. 1:2:10 or 10:-1:1

view this post on Zulip Anton (Dec 26 2025 at 17:57):

In general we like to avoid adding things (like a range type), do you think it would be worth it in this case?

view this post on Zulip Richard Feldman (Dec 26 2025 at 18:13):

yeah I'd like to avoid a dedicated range syntax

view this post on Zulip Richard Feldman (Dec 26 2025 at 18:13):

I don't think it's worth the complexity when we already have like 1.to(5)

view this post on Zulip nandi (Dec 26 2025 at 18:30):

I just cooked up a Range module in userspace

Range.with_step(1, 3, 15) - start=1, step=3, end=15
  to_list: List.[1, 4, 7, 10, 13]

Range.with_step(10, -1, 1) - equivalent to Julia's 10:-1:1
  to_list: List.[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

view this post on Zulip Fabian Schmalzried (Dec 26 2025 at 18:33):

Dynamic dispatch would allow something like 10.steps(2).until(20), but I think 10.until_stepped(20,2) would be good enough.

view this post on Zulip Ian McLerran (Dec 26 2025 at 18:40):

PR to add to and until (just matches current U8 behavior) for all number types except floats:
https://github.com/roc-lang/roc/pull/8763


Last updated: Jan 12 2026 at 12:19 UTC