Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Common type functions
- data Nat :: *
- data Symbol :: *
- natValue :: forall (n :: Nat) a. (KnownNat n, Num a) => a
- natValue' :: forall (n :: Nat). KnownNat n => Word
- symbolValue :: forall (s :: Symbol). KnownSymbol s => String
- class KnownNat (n :: Nat)
- class KnownSymbol (n :: Symbol)
- type family CmpNat (a :: Nat) (b :: Nat) :: Ordering where ...
- type family CmpSymbol (a :: Symbol) (b :: Symbol) :: Ordering where ...
- type family (a :: Nat) <=? (b :: Nat) :: Bool where ...
- type (<=) (x :: Nat) (y :: Nat) = (~) Bool ((<=?) x y) True
- type family (a :: Nat) + (b :: Nat) :: Nat where ...
- type family (a :: Nat) - (b :: Nat) :: Nat where ...
- type family (a :: Nat) * (b :: Nat) :: Nat where ...
- type family (a :: Nat) ^ (b :: Nat) :: Nat where ...
- type family Assert (prop :: Bool) (val :: k) (msg :: ErrorMessage) where ...
- type family If (c :: Bool) (t :: k) (e :: k) where ...
- type family Modulo (a :: Nat) (b :: Nat) where ...
- type family Same a b :: Nat where ...
- data Proxy k (t :: k) :: forall k. k -> * = Proxy
- type family TypeError b (a :: ErrorMessage) :: b where ...
- data ErrorMessage :: * where
Documentation
(Kind) This is the kind of type-level symbols. Declared here because class IP needs it
symbolValue :: forall (s :: Symbol). KnownSymbol s => String Source #
Get a Symbol value
This class gives the integer associated with a type-level natural. There are instances of the class for every concrete literal: 0, 1, 2, etc.
Since: 4.7.0.0
natSing
class KnownSymbol (n :: Symbol) #
This class gives the string associated with a type-level symbol. There are instances of the class for every concrete literal: "hello", etc.
Since: 4.7.0.0
symbolSing
type family CmpNat (a :: Nat) (b :: Nat) :: Ordering where ... #
Comparison of type-level naturals, as a function.
Since: 4.7.0.0
type family CmpSymbol (a :: Symbol) (b :: Symbol) :: Ordering where ... #
Comparison of type-level symbols, as a function.
Since: 4.7.0.0
type family (a :: Nat) <=? (b :: Nat) :: Bool where ... infix 4 #
Comparison of type-level naturals, as a function.
NOTE: The functionality for this function should be subsumed
by CmpNat
, so this might go away in the future.
Please let us know, if you encounter discrepancies between the two.
type (<=) (x :: Nat) (y :: Nat) = (~) Bool ((<=?) x y) True infix 4 #
Comparison of type-level naturals, as a constraint.
type family (a :: Nat) - (b :: Nat) :: Nat where ... infixl 6 #
Subtraction of type-level naturals.
Since: 4.7.0.0
type family (a :: Nat) * (b :: Nat) :: Nat where ... infixl 7 #
Multiplication of type-level naturals.
type family (a :: Nat) ^ (b :: Nat) :: Nat where ... infixr 8 #
Exponentiation of type-level naturals.
type family Assert (prop :: Bool) (val :: k) (msg :: ErrorMessage) where ... Source #
Like: If cond t (TypeError msg)
The difference is that the TypeError doesn't appear in the RHS of the type which lead to better error messages (see GHC #14771).
For instance: type family F n where F n = If (n <=? 8) Int8 (TypeError (Text ERROR))
type family G n where G n = Assert (n <=? 8) Int8 (Text ERROR)
If GHC cannot solve `F n ~ Word`, it shows: ERROR
If GHC cannot solve `G n ~ Word`, it shows:
can't match ..
with Word
data Proxy k (t :: k) :: forall k. k -> * #
A concrete, poly-kinded proxy type
Generic1 k (Proxy k) | |
Monad (Proxy *) | Since: 4.7.0.0 |
Functor (Proxy *) | Since: 4.7.0.0 |
Applicative (Proxy *) | Since: 4.7.0.0 |
Foldable (Proxy *) | Since: 4.7.0.0 |
Traversable (Proxy *) | Since: 4.7.0.0 |
Eq1 (Proxy *) | Since: 4.9.0.0 |
Ord1 (Proxy *) | Since: 4.9.0.0 |
Read1 (Proxy *) | Since: 4.9.0.0 |
Show1 (Proxy *) | Since: 4.9.0.0 |
Alternative (Proxy *) | Since: 4.9.0.0 |
MonadPlus (Proxy *) | Since: 4.9.0.0 |
Hashable1 (Proxy *) | |
Bounded (Proxy k t) | |
Enum (Proxy k s) | Since: 4.7.0.0 |
Eq (Proxy k s) | Since: 4.7.0.0 |
Ord (Proxy k s) | Since: 4.7.0.0 |
Read (Proxy k s) | Since: 4.7.0.0 |
Show (Proxy k s) | Since: 4.7.0.0 |
Ix (Proxy k s) | Since: 4.7.0.0 |
Generic (Proxy k t) | |
Semigroup (Proxy k s) | Since: 4.9.0.0 |
Monoid (Proxy k s) | Since: 4.7.0.0 |
Hashable (Proxy k a) | |
type Rep1 k (Proxy k) | |
type Rep (Proxy k t) | |
type family TypeError b (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: 4.9.0.0
data ErrorMessage :: * where #
A description of a custom type error.
Text :: ErrorMessage | Show the text as is. |
ShowType :: ErrorMessage | Pretty print the type.
|
(:<>:) :: ErrorMessage infixl 6 | Put two pieces of error message next to each other. |
(:$$:) :: ErrorMessage infixl 5 | Stack two pieces of error message on top of each other. |