Created
November 9, 2018 05:00
-
-
Save kozross/ed96329a3b241e7599f1b71aaf8f8394 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newtype Atom = | |
Atom Word64 | |
preview :: Atom -> (Maybe Bool, Word64) | |
preview x = | |
let raw = coerce x | |
f = shorten raw | |
in if | testBit raw 63 -> (Nothing, f) | |
| testBit raw 62 -> (Just False, f) | |
| otherwise -> (Just True, f) | |
review :: (Maybe Bool, Word64) -> Atom | |
review (b, f) = | |
let f = shorten f | |
in case b of | |
Nothing -> coerce (bit 63 .|. f) | |
Just False -> coerce (bit 62 .|. f) | |
Just True -> coerce f | |
-- I want to have a pattern for Present, which unpacks to (Bool, Word64), and a pattern for Absent, which unpacks to just Word64. | |
-- So basically it needs to fake this: | |
-- data AtomB = Present (Bool, Word64) | Absent Word64 | |
-- How would I write these? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.