module Data.BTree.Primitives.Height where
import Data.Binary (Binary)
import Data.Word (Word8)
import Unsafe.Coerce
data Nat = Z | S Nat
newtype Height (h :: Nat) = Height { fromHeight :: Word8 }
deriving (Binary, Eq, Ord)
instance Show (Height h) where
showsPrec p = showsPrec p . fromHeight
zeroHeight :: Height 'Z
zeroHeight = Height 0
incrHeight :: Height h -> Height ('S h)
incrHeight = Height . (+1) . fromHeight
decrHeight :: Height ('S h) -> Height h
decrHeight = Height . (+(1)) . fromHeight
data UHeight (height :: Nat) :: * where
UZero :: UHeight 'Z
USucc :: Height height -> UHeight ('S height)
viewHeight :: Height height -> UHeight height
viewHeight (Height 0) = unsafeCoerce UZero
viewHeight (Height n) = unsafeCoerce (USucc (Height (n1)))