[Haskell] [ANNOUNCE] network-address-0.2.0
sebnow at gmail.com
Thu Sep 8 16:23:31 CEST 2011
On Thu, Sep 8, 2011 at 10:19 AM, Conrad Parker <conrad at metadecks.org> wrote:
> On 7 September 2011 20:03, Sebastian Nowicki <sebnow at gmail.com> wrote:
>> Hi All,
>> I'm pleased to announce the release of network-address v0.2.0. The
>> library provides data structures and textual representation of network
>> addresses (IPv4, IPv6, subnets).
>> Major changes in this release:
>> * Revised Address type class (readAddress was moved out of the class,
>> readsAddress :: String -> ReadS a was added for better error
>> * Better support for IPv6 parsing (compressed zeroes).
>> * Implementation of RFC5952 (a recommendation for IPv6 text
>> representation). Most notably showAddress for IPv6 compresses zeroes.
>> Example GHCi session:
>> *Data.Network.Address> let ip = readAddress "2001:db8:0:0:0::1" :: IPv6
>> *Data.Network.Address> ip
>> IPv6 2306139568115548160 1
>> *Data.Network.Address> showAddress ip
>> *Data.Network.Address> let subnet = readSubnet "2001:db8::1/56" :: IPSubnet IPv6
>> *Data.Network.Address> showSubnet subnet
>> *Data.Network.Address> ip `member` subnet
> given that readAddress can parse the output of showAddress, and
> readSubnet can parse the output of showSubnet, is there any reason not
> to use these for the implementation of Show and Read instances?
No reason other than semantics. I did originally provide custom
Address/Subnet instances which just parsed/printed plain
addresses/subnets. After reading the documentation of Show, which
states that "the result of show is a syntactically correct Haskell
expression", I decided to expose a read function which acted as a
constructor. That resulted in show actually producing "readIPv4
\"192.168.1.1\"", but that seemed silly so I opted for the current
I don't know if it's generally accepted to provide Read/Show instances
which don't parse/print Haskell syntax.
> I notice that currently you deriving Show and Read instances:
> -- |The abstract data structure to represent an IPv4 address.
> data IPv4 = IPv4 !Word32
> deriving (Eq, Ord, Bounded, Show, Read)
> -- |The abstract data structure to represent an IPv6 address.
> data IPv6 = IPv6 !Word64 !Word64
> deriving (Eq, Ord, Show, Read)
> resulting in strings like "IPv6 2306139568115548160 1" above. I can't
> really see a use for that big number representation (other than for
> debugging the library...) so why not just use your existing
> show*/read* functions?
>> Planned for the next release:
>> * Support for parsing IPv4 notation embedded in IPv6 (e.g. "::192.168.1.1")
> is the result a value of type IPv4 or IPv6? For an IPv4-Compatible
> address I'd expect the result to be IPv4. It might also be useful to
> add a conversion function to turn an IPv4 address into an IPv4-Mapped
> IPv6 address.
Technically it's an IPv6 address, "::192.168.1.1" isn't a valid IPv4
string (hence parsing should fail). You can convert from one address
to another using toAddress . fromAddress, i.e.:
(toAddress . fromAddress $ (readAddress "192.168.1.1" :: IPv4)) :: IPv6
More information about the Haskell