Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Fcf.Utils
Description
Miscellaneous families.
Synopsis
- data Error (b :: Symbol) (c :: a)
- data TError (b :: ErrorMessage) (c :: a)
- data Constraints (a :: [Constraint]) b
- data TyEq (c :: a) (d :: b) (e :: Bool)
- type family Stuck :: a
- class IsBool (b :: Bool) where
- data Case (a :: [Match j k]) (b :: j) (c :: k)
- data Match j k
- type (-->) = 'Match_ :: j -> k -> Match j k
- type Is = 'Is_ :: (j -> Exp Bool) -> k -> Match j k
- type Any = 'Any_ :: k -> Match j k
- type Else = 'Else_ :: (j -> Exp k) -> Match j k
- type family If (cond :: Bool) (tru :: k) (fls :: k) :: k where ...
- data Assert (a :: ErrorMessage) (b :: Exp Bool) (c :: r) (d :: r)
- data AssertNot (a :: ErrorMessage) (b :: Exp Bool) (c :: r) (d :: r)
- data ErrorMessage
- type family TypeError (a :: ErrorMessage) :: b where ...
Documentation
data TError (b :: ErrorMessage) (c :: a) Source #
TypeError
as a fcf.
data Constraints (a :: [Constraint]) b Source #
Conjunction of a list of constraints.
Instances
type Eval (Constraints (a ': as) :: Constraint -> Type) Source # | |
Defined in Fcf.Utils | |
type Eval (Constraints ('[] :: [Constraint])) Source # | |
Defined in Fcf.Utils |
data Case (a :: [Match j k]) (b :: j) (c :: k) Source #
(Limited) equivalent of \case { .. }
syntax. Supports matching of exact
values (-->
) and final matches for any value (Any
) or for passing value
to subcomputation (Else
). Examples:
type BoolToNat =Case
[ 'True-->
0 , 'False-->
1 ] type NatToBool =Case
[ 0-->
'False ,Any
'True ] type ZeroOneOrSucc =Case
[ 0-->
0 , 1-->
1 ,Else
((+
) 1) ]
type Is = 'Is_ :: (j -> Exp Bool) -> k -> Match j k Source #
Match on predicate being successful with type in Case
.
type Any = 'Any_ :: k -> Match j k Source #
Match any type in Case
. Should be used as a final branch.
Note: this identifier conflicts with Any
(from Fcf.Class.Foldable)
Any
(from Data.Monoid), and Any
(from GHC.Exts).
We recommend importing this one qualified.
type Else = 'Else_ :: (j -> Exp k) -> Match j k Source #
Pass type being matched in Case
to subcomputation. Should be used as a
final branch.
From Data.Type.Bool
type family If (cond :: Bool) (tru :: k) (fls :: k) :: k where ... #
Type-level If. If True a b
==> a
; If False a b
==> b
Compile-time asserts
data Assert (a :: ErrorMessage) (b :: Exp Bool) (c :: r) (d :: r) Source #
data AssertNot (a :: ErrorMessage) (b :: Exp Bool) (c :: r) (d :: r) Source #
Reexports
data ErrorMessage #
A description of a custom type error.
Constructors
Text Symbol | Show the text as is. |
ShowType t | Pretty print the type.
|
ErrorMessage :<>: ErrorMessage infixl 6 | Put two pieces of error message next to each other. |
ErrorMessage :$$: ErrorMessage infixl 5 | Stack two pieces of error message on top of each other. |
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