Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create pure interface for Address type. #1

Open
Mokosha opened this issue May 30, 2020 · 0 comments
Open

Create pure interface for Address type. #1

Mokosha opened this issue May 30, 2020 · 0 comments

Comments

@Mokosha
Copy link
Owner

Mokosha commented May 30, 2020

Currently, in the high level bindings we store the address type using a ForeignPtr. This is fine, since the C library may have different representations in memory. It has the unfortunate wart of requiring all interfaces that take an Address to be in the IO monad though. It would likely be cleaner to interpret the memory representation into a high-level datatype. Probably something that looks like this:

newtype IPv4Address = IPv4Address (Word8, Word8, Word8, Word8)
  deriving (Eq, Ord, Show, Read, Bounded)
newtype IPv6Address = IPv6Address (Word16, Word16, Word16, Word16, Word16, Word16, Word16, Word16)
  deriving (Eq, Ord, Show, Read, Bounded)

data Address = Address'IPv4 !Word16 !IPv4Address
             | Address'IPv6 !Word16 !IPv6Address
  deriving (Eq, Ord, Show, Read, Bounded)

After this change, the only functions that need IO will be those that convert between memory representations and Haskell (like parseAddress). Others (like the Eq typeclass or addressPort) will not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant