type-digits- Arbitrary-base type-level digits

Portabilitysee LANGUAGE pragmas (... GHC)
Safe HaskellNone



Type-level numerals built from type-level digits of an arbitrary radix.



digit :: (Show a, Eq a, Num a) => a -> NameSource

Convert a number to the name of the corresponding digit -- error if the argument is out of range.

toType :: [Name] -> Type -> TypeSource

Give a list of digit names, and a base type, yields a type.

toType_ :: [Name] -> TypeSource

toType_ = ($ TupleT 0) . toType.

toDigits :: (a -> [Name]) -> a -> Type -> TypeSource

toDigits f = toType . f

toDigits_ :: (a -> [Name]) -> a -> TypeSource

toDigits_ = (($ TupleT 0) .) . toDigits.

flexible :: (Show a, Eq a, Integral a) => a -> [Name]Source

Converts an Integral to a type-level numeral using as many digits as it takes that particular number.

fixed :: forall a. (Bounded a, Show a, Eq a, Integral a) => a -> [Name]Source

Converts a Bounded Integral to a type-level numeral using exactly the number of digits it takes to represent each value of that type uniquely.

flexible' :: Enum a => a -> [Name]Source

flexible' = flexible . fromEnum

fixed' :: Enum a => a -> [Name]Source

fixed' = fixed . fromEnum

exactly :: Int -> [Name] -> [Name]Source

Pads its second argument so that the resulting length is its first argument; fails if the second argument is already larger.