Open ppetr opened 8 years ago
So, do you mean that these function should be polymorphic? Anyway, please show your code to me.
My current code for the network package is here: https://github.com/haskell/network/pull/210 (sorry for the confusion before). At the end I thought that it'd be better suited for the network package directly, but perhaps both packages could benefit from such functions.
No, I had no polymorphism on my mind. IPv4 addresses are defined to be 4 8-byte unsigned numbers and IPv6 as 8 16-byte unsigned numbers, so my suggestion is to add functions that convert to precisely such a representation. And to use tuples instead of lists, as conversions from list are partial functions (are well defined only if the argument has the correct length), while conversions from tuples are total functions. Making them polymorphic might make their use easier, but might cause errors if they're used on an inappropriate integral instance, so I'd rather keep them with the exact correct type,.although I'm open to discussion.
Currently various
from...
/to...
functions work with just[Int]
. I'd suggest to:Word8
forto/fromIPv4
andto/fromIPv6b
, andWord16
forto/fromIPv6
.from/toIPv6
andfrom/toIPv4
that take/return 4-tuples and 8-tuples instead of lists. This is safer, and it's still possible to efficiently work with such tuples by wrapping them for example withNTup4
/NTup8
which provideTraversable
,Applicative
etc.I'll be happy to contribute, if we agree on this.