isobmff-0.13.0.0: A parser and generator for the ISO-14496-12/14 base media file format

Safe HaskellNone
LanguageHaskell2010

Data.Type.BitRecords.Assert

Description

Type - level assertion utility leveraging custom TypeErrors

Synopsis

Documentation

type family Assert (cond :: Assertion a) (x :: a) :: a where ... Source #

Apply an Assertion to some value and return that value if the assertion holds, otherwise throw a TypeError.

Equations

Assert cond x = ProcessCheckResult (Check cond x) x 

type Assertion a = TyFun a (Maybe ErrorMessage) -> Type Source #

Make an assertion by creating a phantom data type which contains TyFun a (Maybe ErrorMessage) as last parameter. Check is used by Assert the apply the TyFuns which are specialized in this definition to have the return type Maybe ErrorMessage.

type family Check (f :: Assertion a) (x :: a) :: Maybe ErrorMessage Source #

Apply Assertions to the actual values.

Instances
type Check (NatLE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (NatLE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) = If (x <=? n) (Nothing :: Maybe ErrorMessage) (Just ((Text "Natural too big: " :<>: ShowType x) :$$: (Text "Required: <=" :<>: ShowType n)))
type Check (NatGE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (NatGE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) = If (n <=? x) (Nothing :: Maybe ErrorMessage) (Just ((Text "Natural too small: " :<>: ShowType x) :$$: (Text "Required: >=" :<>: ShowType n)))
type Check (NatIn from to :: TyFun Nat (Maybe ErrorMessage) -> Type) (n :: Nat) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (NatIn from to :: TyFun Nat (Maybe ErrorMessage) -> Type) (n :: Nat)
type Check (LengthIn from to :: TyFun k (Maybe ErrorMessage) -> Type) (xs :: k) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (LengthIn from to :: TyFun k (Maybe ErrorMessage) -> Type) (xs :: k) = Check (NatIn from to) (CountElementsForLengthIn xs)
type Check (a1 @&& a2 :: TyFun (Maybe ErrorMessage) (Maybe ErrorMessage) -> Type) (x :: Maybe ErrorMessage) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (a1 @&& a2 :: TyFun (Maybe ErrorMessage) (Maybe ErrorMessage) -> Type) (x :: Maybe ErrorMessage)

type (?::) x cond = Assert cond x infixr 0 Source #

Assert that a given type satisfies some condition defined via Check instances. This is only an alias for Assert

data (@&&) :: Assertion a -> Assertion a -> Assertion a Source #

Assert that two assertions both hold

Instances
type Check (a1 @&& a2 :: TyFun (Maybe ErrorMessage) (Maybe ErrorMessage) -> Type) (x :: Maybe ErrorMessage) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (a1 @&& a2 :: TyFun (Maybe ErrorMessage) (Maybe ErrorMessage) -> Type) (x :: Maybe ErrorMessage)

data NatLE :: Nat -> Assertion Nat Source #

Assert that a Nat is less than or equal to an other Nat.

Instances
type Check (NatLE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (NatLE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) = If (x <=? n) (Nothing :: Maybe ErrorMessage) (Just ((Text "Natural too big: " :<>: ShowType x) :$$: (Text "Required: <=" :<>: ShowType n)))

data NatGE :: Nat -> Assertion Nat Source #

Assert that a Nat is greater than or equal to an other Nat.

Instances
type Check (NatGE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (NatGE n :: TyFun Nat (Maybe ErrorMessage) -> Type) (x :: Nat) = If (n <=? x) (Nothing :: Maybe ErrorMessage) (Just ((Text "Natural too small: " :<>: ShowType x) :$$: (Text "Required: >=" :<>: ShowType n)))

data NatIn :: Nat -> Nat -> Assertion Nat Source #

Assert that a Nat is in a specific range.

Instances
type Check (NatIn from to :: TyFun Nat (Maybe ErrorMessage) -> Type) (n :: Nat) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (NatIn from to :: TyFun Nat (Maybe ErrorMessage) -> Type) (n :: Nat)

data LengthIn :: Nat -> Nat -> Assertion a Source #

Assert that a list's length falls into a given range. This is generalized from actual lists; everything with a CountElementsForLengthIn instance can be asserted.

Instances
type Check (LengthIn from to :: TyFun k (Maybe ErrorMessage) -> Type) (xs :: k) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type Check (LengthIn from to :: TyFun k (Maybe ErrorMessage) -> Type) (xs :: k) = Check (NatIn from to) (CountElementsForLengthIn xs)

type family CountElementsForLengthIn (xs :: k) :: Nat Source #

Instances
type CountElementsForLengthIn ([] :: [k]) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert

type CountElementsForLengthIn ([] :: [k]) = 0
type CountElementsForLengthIn (x ': xs :: [a]) Source # 
Instance details

Defined in Data.Type.BitRecords.Assert