-- this mostly a direct copy of https://github.com/AndrasKovacs/smalltt/blob/b5fc9b3747dcbf8c71ca9f976afb7b574b630996/src/LvlSet.hs
-- see LICENSE.smalltt for license information
newtype ScopeMask = ScopeMask Integer via Integer
(<>) = (.|.)
mempty = ScopeMask 0
ScopeMask (unsafeShiftL 1 x .|. s)
(unsafeShiftL 1 x .&. s) /= 0
reverse $ intern 0 s'
where
-- | `intern offset smask`
[]
intern i (ScopeMask s) =
let nxt = intern (i + 1) (ScopeMask $ unsafeShiftR s 1) in
if 1 .&. s /= 0 then i:nxt else nxt
foldl' (flip insert) mempty
show = show . toList