typelevel-1.2.3: Useful type level operations (type families and related operators).

Safe HaskellNone
LanguageHaskell2010

Type.Error_old

Synopsis

Documentation

type (:</>:) a b = (a :<>: ErrMsg " ") :<>: b Source #

type Between' s a = Between s s a Source #

type Between l r a = (ErrMsg l :<>: a) :<>: ErrMsg r Source #

type Parensed a = Between "(" ")" a Source #

type Ticked a = Between' "`" a Source #

type Sentence a = a :<>: ErrMsg "." Source #

type Assert' ok = Assert ok (ErrMsg "Assertion failed.") Source #

class Assert (ok :: Bool) (err :: ErrorMessage) Source #

Instances
(TypeError err :: Constraint) => Assert False err Source # 
Instance details

Defined in Type.Error_old

Assert True err Source # 
Instance details

Defined in Type.Error_old

type family TypeError (a :: ErrorMessage) :: b where ... #

The type-level equivalent of error.

The polymorphic kind of this type allows it to be used in several settings. For instance, it can be used as a constraint, e.g. to provide a better error message for a non-existent instance,

-- in a context
instance TypeError (Text "Cannot Show functions." :$$:
                    Text "Perhaps there is a missing argument?")
      => Show (a -> b) where
    showsPrec = error "unreachable"

It can also be placed on the right-hand side of a type-level function to provide an error for an invalid case,

type family ByteSize x where
   ByteSize Word16   = 2
   ByteSize Word8    = 1
   ByteSize a        = TypeError (Text "The type " :<>: ShowType a :<>:
                                  Text " is not exportable.")

Since: base-4.9.0.0

data ErrorMessage where #

A description of a custom type error.

Constructors

ShowType :: forall t. t -> ErrorMessage

Pretty print the type. ShowType :: k -> ErrorMessage

(:<>:) :: forall. ErrorMessage -> ErrorMessage -> ErrorMessage infixl 6

Put two pieces of error message next to each other.

(:$$:) :: forall. ErrorMessage -> ErrorMessage -> ErrorMessage infixl 5

Stack two pieces of error message on top of each other.