Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Last active January 18, 2021 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/ffcd090e13437b75bde98a61d3b08858 to your computer and use it in GitHub Desktop.
Save dminuoso/ffcd090e13437b75bde98a61d3b08858 to your computer and use it in GitHub Desktop.
split4 :: IPv4Range -> Maybe (IPv4Range, IPv4Range)
split4 (IPv4Range b l)
| l < 32 = Just (upper, lower)
| otherwise = Nothing
where
lower = range b (l + 1)
upper = range (b `setBit` (31 - fromIntegral l)) (l + 1)
split6 :: IPv6Range -> Maybe (IPv6Range, IPv6Range)
split6 n (IPv6Range b l)
| l < 128 = Just (upper, lower)
| otherwise = Nothing
where
lower = range b (l + 1)
upper = range (b `setBit` (127 - fromIntegral l)) (l + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment