HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulegenerics-sop-0.5.1.4Haskell2010

Generics.SOP.Constraint

  • 4 types
  • 7 classes
  • 1 value
classclass (AllF c xs, SListI xs) => All (c :: k -> Constraint) (xs :: [k]) where
#

Require a constraint for every element of a list.

If you have a datatype that is indexed over a type-level list, then you can use All to indicate that all elements of that type-level list must satisfy a given constraint.

Example: The constraint

All Eq '[ Int, Bool, Char ]

is equivalent to the constraint

(Eq Int, Eq Bool, Eq Char)

Example: A type signature such as

f :: All Eq xs => NP I xs -> ...

means that f can assume that all elements of the n-ary product satisfy Eq.

Note on superclasses: ghc cannot deduce superclasses from All constraints. You might expect the following to compile

class (Eq a) => MyClass a

foo :: (All Eq xs) => NP f xs -> z
foo = [..]

bar :: (All MyClass xs) => NP f xs -> x
bar = foo

but it will fail with an error saying that it was unable to deduce the class constraint AllF Eq xs (or similar) in the definition of bar. In cases like this you can use Dict from Data.SOP.Dict to prove conversions between constraints. See this answer on SO for more details.

Methods

  • cpara_SList :: proxy c -> r '[] -> (forall (y :: k) (ys :: [k]). (c y, All c ys) => r ys -> r (y ': ys)) -> r xs

    Constrained paramorphism for a type-level list.

    The advantage of writing functions in terms of cpara_SList is that they are then typically not recursive, and can be unfolded statically if the type-level list is statically known.

Instances2All
  • All c '[]Defined in sop-core-0.5.0.2 · Data.SOP.Constraint
  • (c x, All c xs) => All c (x ': xs)Defined in sop-core-0.5.0.2 · Data.SOP.Constraint
typetype All2 (c :: k -> Constraint) = All (All c)
#

Require a constraint for every element of a list of lists.

If you have a datatype that is indexed over a type-level list of lists, then you can use All2 to indicate that all elements of the inner lists must satisfy a given constraint.

Example: The constraint

All2 Eq '[ '[ Int ], '[ Bool, Char ] ]

is equivalent to the constraint

(Eq Int, Eq Bool, Eq Char)

Example: A type signature such as

f :: All2 Eq xss => SOP I xs -> ...

means that f can assume that all elements of the sum of product satisfy Eq.

Since 0.4.0.0, this is merely a synonym for 'All (All c)'.

valueccase_SList
  1. :: All c xs
  2. => proxy c
  3. -> r '[]
  4. -> forall (y :: a) (ys :: [a]). (c y, All c ys) => r (y ': ys)
  5. -> r xs
#

Constrained case distinction on a type-level list.

classclass (SListI xs, SListI ys, SameShapeAs xs ys, SameShapeAs ys xs, AllZipF c xs ys) => AllZip (c :: a -> b -> Constraint) (xs :: [a]) (ys :: [b])
#

Require a constraint pointwise for every pair of elements from two lists.

Example: The constraint

AllZip (~) '[ Int, Bool, Char ] '[ a, b, c ]

is equivalent to the constraint

(Int ~ a, Bool ~ b, Char ~ c)
Instances1AllZip
familytype family AllN (h :: (k -> Type) -> l -> Type) (c :: k -> Constraint) :: l -> Constraint
#

A generalization of All and All2.

The family AllN expands to All or All2 depending on whether the argument is indexed by a list or a list of lists.

Instances4AllN
  • type AllN NP c = All cDefined in sop-core-0.5.0.2 · Data.SOP.NP
  • type AllN POP c = All2 cDefined in sop-core-0.5.0.2 · Data.SOP.NP
  • type AllN NS c = All cDefined in sop-core-0.5.0.2 · Data.SOP.NS
  • type AllN SOP c = All2 cDefined in sop-core-0.5.0.2 · Data.SOP.NS
classclass f (g x) => Compose (f :: k -> Constraint) (g :: k1 -> k) (x :: k1)
#

Composition of constraints.

Note that the result of the composition must be a constraint, and therefore, in Compose f g, the kind of f is k -> Constraint. The kind of g, however, is l -> k and can thus be a normal type constructor.

A typical use case is in connection with All on an Data.SOP.NP or an Data.SOP.NS. For example, in order to denote that all elements on an Data.SOP.NP f xs satisfy Show, we can say All (Compose Show f) xs.

Instances1Compose
  • f (g x) => Compose f g xDefined in sop-core-0.5.0.2 · Data.SOP.Constraint
classclass (f x, g x) => And (f :: k -> Constraint) (g :: k -> Constraint) (x :: k)
#

Pairing of constraints.

Instances1And
  • (f x, g x) => And f g xDefined in sop-core-0.5.0.2 · Data.SOP.Constraint
classclass Top (x :: k)
#

A constraint that can always be satisfied.

Instances1Top
  • Top xDefined in sop-core-0.5.0.2 · Data.SOP.Constraint
familytype family SameShapeAs (xs :: [a]) (ys :: [b]) :: Constraint where
#

Type family that forces a type-level list to be of the same shape as the given type-level list.

Since 0.5.0.0, this only tests the top-level structure of the list, and is intended to be used in conjunction with a separate construct (such as the AllZip, AllZipF combination to tie the recursive knot). The reason is that making SameShapeAs directly recursive leads to quadratic compile times.

The main use of this constraint is to help type inference to learn something about otherwise unknown type-level lists.

Equations

typetype SListI = All Top
#

Implicit singleton list.

A singleton list can be used to reveal the structure of a type-level list argument that the function is quantified over.

Since 0.4.0.0, this is now defined in terms of All. A singleton list provides a witness for a type-level list where the elements need not satisfy any additional constraints.

typetype SListI2 = All SListI
#

Require a singleton for every inner list in a list of lists.

familytype family Head (xs :: [a]) :: a where
#

Utility function to compute the head of a type-level list.

Equations

familytype family SListIN (h :: (k -> Type) -> l -> Type) :: l -> Constraint
#

A generalization of SListI.

The family SListIN expands to SListI or SListI2 depending on whether the argument is indexed by a list or a list of lists.

Instances4SListIN
familytype family Tail (xs :: [a]) :: [a] where
#

Utility function to compute the tail of a type-level list.

Equations