Closed erantapaa closed 8 years ago
I agree that it's desirable to have such a functions (especially for unit testing etc).
Here are some questions I had in mind when I decided not to supply them:
[Word8]
/ [Word16]
, but those are non-total. How to deal with invalid input?inetCustom :: Word8 -> Word8 -> Word8 -> Word8 -> InetAddress
inet6Custom :: Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Word16 -> Inet6Address
How about adopting the signatures use by the network package, i.e. see the tupleToHostAddress
and tupleToHostAddress6
functions:
https://hackage.haskell.org/package/network-2.6.3.1/docs/Network-Socket.html#v:hostAddressToTuple
There are some other Haskell libraries which deal with IPv4 and IPv6 addresses to compare with - I'll try to dig them up.
Some other packages to look at:
network-ip: https://hackage.haskell.org/package/network-ip-0.3/docs/Network-IP-Addr.html
ip-route: https://hackage.haskell.org/package/iproute-1.7.0/docs/Data-IP.html#t:IPv4
I personally like the tupleToX
and XtoTuple
from the network package the most.
ip-route
is non-total. network-ip
supplies toWords
and fromWord
, but they are not exact counter parts wrt. to type signature.
I'd like to add the following to the library:
inetAddressToTuple :: InetAddress -> (Word8, Word8, Word8, Word8)
inetAddressFromTuple :: (Word8, Word8, Word8, Word8) -> InetAddress
inet6AddressToTuple :: Inet6Address -> (Word16,Word16,Word16,Word16,Word16,Word16,Word16,Word16)
inet6AddressFromTuple :: (Word16,Word16,Word16,Word16,Word16,Word16,Word16,Word16) -> Inet6Address
Do you agree?
That's fine. As long as there is a way to construct a value without resorting to IO.
Other people can then create whatever interface they want.
Just pushed a commit with the additions.
Changes are in v0.6.2.0 on Hackage.
It would be nice if there was a way of creating an InetAddress without having to go into the IO-monad. The only way I can see to do it is to use
getAddressInfo
.I.e. it would be nice to have functions like:
Also see this SO thread: http://stackoverflow.com/q/38770829/866915