On 10/3/05, Joel Reymont <joelr1@gmail.com> wrote:
Folks,
Are there any endian conversion routines for Haskell? I'm looking to
build binary packets on top of NewBinary.Binary but my data is coming
in little-endian whereas I'll need to send it out big endian.
>From your question I assume you want functions like htonl / ntohl.
I think the cleanest approach is to always have yours Ints, etc in host order, and place
the endianness stuff in serialization / deserialization code, ie. on the Number <-> Byte
sequence boundary.
Having htonl/ntohl as pure functions in Haskell would be a bit ugly, because
they would be defined differently on different platforms, and putting them in the
IO monad would make them barely usable.
Best regards
Tomasz