so ive tried solving some aoc stuff in roc and compared to haskell having to convert to and from a list is kind of boilerplate-y, are there any specific reasons for strings not just being a distinct list of bytes
For AOC I think most people should just directly use a List U8
and not attempt to use strings at all. Fundamentally, a Str
is guaranteed to be valid utf-8. That adds extra constraints and restrictions. On top of that, it is exceptionally easy to misuse unicode and have subtle bugs. We have a partially built unicode library that enables more powerful operations over strings, but in general, we are trying to push people towards correct design when using strings and that often requires extra thought and constraints.
For AOC, everything is ASCII. So it has no need to be a string at all.
We should really make an advent of code example that demonstrates the best practices, I've made an issue.
I had the same question many times. If Str is an alias for List U8, all arguments for correct design would still be true. The Unicode package could still exist and work on Str/List U8.
There are many similar functions in the List and Str packets, that could be unified, if both types would be the same. And with the planned small list optimisation, there would be no different.
Yeah, the only difference really is that str will be guaranteed to be correctly encoded utf-8
It also attempts to restrict a few apis to make it more clear when someone might be using said utf-8 incorrectly. But currently those apis differences are pretty minimal
Last updated: Jul 06 2025 at 12:14 UTC