DerivingStrategies #-}
module Main where
import GHC.TypeLits
import Data.Type.Bool
import GHC.Types
import Data.Word
main = print (64 `is` Word6)
data Proxy a = MkProxy
is :: forall (n :: Nat) -> KnownNat n => forall a -> TypedFromIntegral n a => a
is n a = fromIntegralTyped @n @a MkProxy
class TypedFromIntegral n a where
fromIntegralTyped :: KnownNat n => Proxy n -> a
newtype Word6 = MkWord6 Word8
deriving newtype Show
instance CheckWord6Size n => TypedFromIntegral n Word6 where
fromIntegralTyped p = MkWord6 $ fromIntegral (natVal p)
type EmptyConstraints :: Constraint
type EmptyConstraints = () -- hack to make kind inference work for (% %)
type CheckWord6Size :: Nat -> Constraint
type family CheckWord6Size n where
CheckWord6Size n =
If (2 ^ 6 <=? n)
(TypeError (Text "Nat Is Out Of Bounds Word6"))
EmptyConstraints
Стикер
Обсуждают сегодня