darcs patch: Implementation of aton and ntoa outside the IO
monad
Samuel Bronson
naesten at gmail.com
Tue Sep 26 09:00:33 EDT 2006
On 9/25/06, Tomasz Zielonka <tomasz.zielonka at gmail.com> wrote:
> On Mon, Sep 25, 2006 at 05:09:13PM +0900, Robert Marlow wrote:
> > I think HostAddresses are probably good how they are now. It seems a bit
> > too much work to convert a HostAddresses endianness everytime it's used.
>
> Do you mean too much work for the programmer or for the computer?
>
> If the latter, then I propose to make HostAddresses an abstract
> newtype, which doesn't allow to observe the endianness of the platform.
I'm surprised it isn't one already... I believe port numbers are.
> Internally it could still keep the address in network order, so no
> conversions would be neccessary. However, the easiest way to implement
> eg. comparisons for such a datatype would be to flip endianness before
> comparing. So you will have to pay the cost of conversion for some
> operations. I would prefer if this cost was associated with network
> operations (connect, sentto, recvfrom, ...), because they already have
> a relatively big cost and you don't call them so often.
How often do you need to do comparisons on addresses for anything but
equality (which doesn't require flipping to test)?
> > If the problem is how it appears (which along with PortAddress can be
> > confusing) perhaps it just needs a different show implementation.
>
> The problem is everything that gives different results on platforms with
> different byte-orders. Show is one example, but there are also arithmetic
> operations, Ord, etc.
... How often do you need to do arithmatic? Oh, btw, there are
ntoh*/hton* functions for converting between host and network byte
orders regardless of how crazy the host byte-order is...
More information about the Libraries
mailing list