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...
Definitely a bug
Should work for any number type
Or at least any integer type.... But I would argue any number type
Looking at Builtins.roc, it looks like it's only defined for U8 right now...
Probably should just be a generic function and then called by each number type
Probably was only added to u8 cause that was requested for AOC
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?
Yeah, like that
I think all need the stub
I'll just add this, no prob!
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
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.
Also, what is our plan for ranges with different step sizes?
Or with negative steps?
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
In general we like to avoid adding things (like a range type), do you think it would be worth it in this case?
yeah I'd like to avoid a dedicated range syntax
I don't think it's worth the complexity when we already have like 1.to(5)
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]
Dynamic dispatch would allow something like 10.steps(2).until(20), but I think 10.until_stepped(20,2) would be good enough.
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