{-# LANGUAGE GHC2024, TemplateHaskell, DerivingStrategies #-} module INTx where import GHC.TypeLits (Nat, KnownNat) import qualified Language.Haskell.TH as TH -- | ABI integer value types, where @s@ is for signess and @n@ is the multiple of 8 bits newtype INTx (s :: Bool) (n :: Nat) = INT Integer deriving newtype (Eq, Ord, Enum) -- | A constraint that restricts what Nat values are valid for 'INTx'. class KnownNat n => ValidINTn n -- | A top-level splice that declares all the valid INTx n values. flip foldMap [1..32] $ \i -> [d| instance ValidINTn $(TH.litT (TH.numTyLit i)) |]