Skip to content

Instantly share code, notes, and snippets.

@kozross
Created November 9, 2018 00:47
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 kozross/c7111bc195dd9f1480130bd810e9ff8b to your computer and use it in GitHub Desktop.
Save kozross/c7111bc195dd9f1480130bd810e9ff8b to your computer and use it in GitHub Desktop.
newtype AtomP = AtomP Word64
view :: AtomP -> Maybe (Bool, Word64)
view x = let mask = complement (bit 63 .|. bit 62)
raw = coerce x in
if | testBit raw 63 -> Nothing
| testBit raw 62 -> Just (False, pext64 raw mask)
| otherwise -> Just (True, pext64 raw mask)
-- I want to expose a view of AtomP as a Maybe (Bool, Word64) on the basis of the function above.
-- I want the view to be read-only (so for pattern matching).
@mstksg
Copy link

mstksg commented Nov 9, 2018

pattern Atom :: Bool -> Word64 -> AtomP
pattern Atom x y <- (view->Just (x, y))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment