[Haskell] [ANNOUNCE] network-address-0.2.0

Sebastian Nowicki sebnow at gmail.com
Thu Sep 8 16:49:17 CEST 2011


On Thu, Sep 8, 2011 at 9:05 PM, Ben Millwood <haskell at benmachine.co.uk> wrote:
> On Wed, Sep 7, 2011 at 1:03 PM, Sebastian Nowicki <sebnow at gmail.com> wrote:
>> The next release will likely be v1.0.0 as there isn't much to add. I'd
>> like to keep the API stable in that version, I welcome any feedback
>> regarding the API (or otherwise).
>
> The main problem is lacking an effective way to parse addresses from
> strings - the readAddress interface is unsafe and doesn't give the
> remainder of the string. Consider using the ReadS convention,
> providing a function readsAddress :: String -> [(a,String)] which
> provides all possible parses (usually at most one) and the remainder
> of the string. Then users can parse addresses followed by other data
> easily.
>
> I'm actually also not clear how I'd actually *use* one of these
> addresses with any network library.

I probably should have looked into this more before creating new data
types. I was focusing on efficient/convenient data storage (e.g.
database) rather than using it in a networking library. Network.Socket
has two address types:

type HostAddress = Word32
type HostAddress6 = (Word32, Word32, Word32, Word32)

For IPv4 it's pretty easy to convert (although ideally you shouldn't have to):

    *Data.Network.Address Network.Socket> let ip = readAddress "8.8.8.8" :: IPv4
    *Data.Network.Address Network.Socket> inet_ntoa . fromInteger .
fromAddress $ ip
    "8.8.8.8"

And of course you can just deconstruct IPv4:

    *Data.Network.Address Network.Socket> let (IPv4 ip') = ip in inet_ntoa ip'
    "8.8.8.8"

IPv6 isn't compatible with HostAddress6 though. Maybe it'd be a good
idea to just write Address instances for HostAddress and HostAddress6.

Is there any other networking library that should be supported?

Regarding using type families for subnets, I wasn't aware of them. I
didn't like the idea of using MPTC and fund eps, but I couldn't think
of a more elegant solution. I'll read up on it. Thanks.



More information about the Haskell mailing list