In the Num module at the moment there are functions for converting a list of bytes to unsigned integers. This set of functions could be extended to also convert integers to list of bytes. I think the user should also be able to specify endianness.
@Richard Feldman you had some thoughts?
yeah, so one thought is that my default preference would be that you have to explicitly specify either big-endian or little-endian
that way, we maintain the property that the same Roc code gives the same answer (or crashes) no matter the system it's run on
native endianness, like Nat (which #ideas > replace Nat concluded should be replaced with U64) violates that unless it's obtained as a Task like it is in Elm
so I think it's safe to assume we should support at least compiling to explicit endianness
but I think there's a reasonable question as to what use cases would want native endianness, and how big of a deal it would be if the only way to obtain that was via a Task
Richard Feldman said:
but I think there's a reasonable question as to what use cases would want native endianness, and how big of a deal it would be if the only way to obtain that was via a
Task
I've never needed native endianness, so I don't think it would be a big deal. The only downside I see is that every platform would need to define it separately. Unless the proposal for language level tasks goes through of course
Actually, I don't know if language level tasks would help :sweat_smile:
But still, I don't think it is a big deal
language level tasks would allow it to be a builtin :thumbs_up:
I think you just need a task to get the endianness of the current system. Then you save it /pass it down the call stack. Don't waste time going to the host for every conversion
Where native endian is needed is going from a binary storage format to the systems format. If you have a proto that stores numbers in little endian and you run on a big endian system, you would need to convert to native get the correct integer.
I think we should require specifying the endianness as well.
Can roc have a built-in that generates a task? If so, i think a built-in task to get the endianness would be a great idea. No need to support it on every platform.
I assume that feature might require future changes to task first
yeah totally - once Task is a builtin, we can just have Num.endianness (or Bytes.endianness; I've been noticing there are a lot of bytes-specific operations, and a Bytes module is sounding increasingly appealing) which returns Task Endianness *
Brendan Hansknecht said:
Where native endian is needed is going from a binary storage format to the systems format. If you have a proto that stores numbers in little endian and you run on a big endian system, you would need to convert to native get the correct integer.
ah, this is an interesting point! We could also separately have a way to convert from bytes that have a specific endianness into specific numbers in memory
which I don't think would require a Task, since you'd be explicitly specifying what endianness the input bytes have, and then once the number is in memory it's essentially opaque in terms of endianness
Kilian Vounckx has marked this topic as resolved.
Ah, so implicit native endian
Cause that doesn't matter once loaded into a number type
That is definitely a better api
Last updated: Jun 16 2026 at 16:19 UTC