HORIZON HASKELLDocslts/ghc-9.14.x45dd5372026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11

Modulefirst-class-families-0.8.2.0Haskell2010

Fcf.Utils

Miscellaneous families.

  • 13 types
  • 1 class
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
familytype family Stuck :: a
#

A stuck type that can be used like a type-level undefined.

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 (-->) = 'Match_
#

Match concrete type in Case.

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.

From Data.Type.Bool

1 declaration
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

2 declarations
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

2 declarations
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.")