HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulefirst-class-families-0.8.2.0Haskell2010

Fcf.Utils

Miscellaneous families.

Contents
  1. From Data.Type.Bool
  2. Compile-time asserts
  3. Reexports
Synopsis
datadata TyEq (c :: a) (d :: b) (e :: Bool)

Type equality.

Details

The base library also defines a similar (Type.Equality.==); it differs from TyEq in the following ways:

  • TyEq is heterogeneous: its arguments may have different kinds;

  • TyEq is reflexive: TyEq a a always reduces to True even if a is a variable.

Instances1Eval
  • type Eval (TyEq a b) = TyEqImpl a bDefined in first-class-families-0.8.2.0 · Fcf.Utils
classclass IsBool (b :: Bool) where
#

Methods

Instances2IsBool
  • IsBool 'FalseDefined in first-class-families-0.8.2.0 · Fcf.Utils
  • IsBool 'TrueDefined in first-class-families-0.8.2.0 · Fcf.Utils
datadata Case (a :: [Match j k]) (b :: j) (c :: k)

(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)
  ]
Instances1Eval
  • type Eval (Case ms a) = Case_ ms aDefined in first-class-families-0.8.2.0 · Fcf.Utils
typetype Is = 'Is_

Match on predicate being successful with type in Case.

typetype Else = 'Else_

Pass type being matched in Case to subcomputation. Should be used as a final branch.

familytype family If (cond :: Bool) (tru :: k) (fls :: k) :: k where

Type-level If. If True a b ==> a; If False a b ==> b

Equations

Compile-time asserts

datadata Assert (a :: ErrorMessage) (b :: Exp Bool) (c :: r) (d :: r)

A compile-time assert.

Raises the provided TypeError, whenever the condition evaluates to False.

Usage example: type ExampleAssertionFailure = Eval ( Pure '["foo", "bar"] >>= Length >>= Assert ('Text Assertion) (TyEq Int Void) )

Instances1Eval

Reexports

familytype 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.")