I'm on Roc compiler version nightly-2026-08-06-61bbb59.
Here is a small example:
main! = |_args| {
a = ["Larry", "Curly", "Moe"]
b = a.swap(0, 2)?
c = b.get(0)?
echo!("${Str.inspect(b)}\n")
echo!("${Str.inspect(c)}\n")
Ok({})
}
Note that the swap and get functions take U64s.
Here is a larger example:
test_names_2 = "Vyrdax,Drakzyph,Fyrryn,Elarzris"
test_dirs_2 = "R3,L2,R3,L3"
main! = |_args| {
var $names = test_names_2.split_on(",")
dirs = test_dirs_2.split_on(",")
for dir in dirs {
right = dir.starts_with("R")
dist = U64.from_str(dir.drop_prefix("R").drop_prefix("L"))
match dist {
Ok(d) => {
index =
if right {
d.mod_by($names.len())
} else {
($names.len() - (d.mod_by($names.len()))).mod_by($names.len())
}
match $names.swap(0.U64, index) {
Ok(new_names) => {
$names = new_names
}
Err(OutOfBounds) => {
crash "bad"
}
}
}
Err(_e) => {
crash "bad"
}
}
}
name = match $names.get(0.U64) {
Ok(s) => s
Err(OutOfBounds) => {
crash "bad"
}
}
echo!("${name}\n")
Ok({})
}
Note that 0.U64 number constants in this larger example (in the swap and get calls). If I don't use the .U64, the compiler complains about not expecting a Dec for those numbers.
When should I use just 0 versus 0.U64?
Thanks!
It seems like we can improve the compiler so you do not need to add the U64.
What do you think of "Option 1" in the file @Jared Ramirez @Richard Feldman?
hm I think Option 2 actually sounds better, particularly:
a var that is both signature-reachable and chain-reachable would become shared-monomorphic instead of quantified, which is a subtle behavior change to audit.
I think that's the behavior that fits let-generalization: let's not
wanna run that by Fable and see if it thinks I'm missing anything? :smile:
maybe there's some edge case I'm not thinking about, but in general we have decided to make literals end up resolving to one monomorphic type for exactly those reasons
(actually I think "let's not" suggested we could make an exception for number literals, but as I recall we decided not to make that exception)
Fable likes option 2 after a deep dive :)
cool, wanna make a PR for it? I can review
Yes, Claude is on it
Nice and small PR#10671
Greptile's comment is accurate :smile:
I have addressed the comment :)
cool, wanna make a PR for it? I can review
Is it good to merge @Richard Feldman?
I'm still pushing revisions :sweat_smile:
Richard Feldman said:
I'm still pushing revisions :sweat_smile:
I'm not sure I understand, do you mean you're working on the same code in other PRs?
oh oops I thought you were referring to a different PR
feel free to merge this one! :+1:
Last updated: Aug 12 2026 at 12:35 UTC