HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulefirst-class-families-0.8.1.0Haskell2010

Fcf.Class.Foldable

Foldable types.

A minimal implementation of this interface is given by either FoldMap or Foldr, but a default still needs to be given explicitly for the other.

data MyType a = ... {- Some custom Foldable type -}

-- Method 1: Implement Foldr, default FoldMap.
type instance Eval (Foldr f y xs) = ... {- Explicit implementation -}
type instance Eval (FoldMap f xs) = FoldMapDefault_ f xs {- Default -}

-- Method 2: Implement FoldMap, default Foldr.
type instance Eval (FoldMap f xs) = ... {- Explicit implementation -}
type instance Eval (Foldr f y xs) = FoldrDefault_ f y xs {- Default -}
  • 11 types

Core interface

2 declarations
datadata Foldr (c :: a -> b -> Exp b) (d :: b) (e :: t a) (f :: b)
#

Right fold.

Example
Example1 expression
:kind! Eval (Foldr (+) 0 [1, 2, 3, 4])Eval (Foldr (+) 0 [1, 2, 3, 4]) :: Natural= 10
Instances6Eval
  • type Eval (Foldr f y 'Nothing) = yDefined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
  • type Eval (Foldr f y '[]) = yDefined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
  • type Eval (Foldr f y ('Left _a)) = yDefined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
  • type Eval (Foldr f y ('Right x)) = Eval (f x y)Defined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
  • type Eval (Foldr f y ('Just x)) = Eval (f x y)Defined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
  • type Eval (Foldr f y (x ': xs)) = Eval (f x (Eval (Foldr f y xs)))Defined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
datadata FoldMap (b :: a -> Exp m) (c :: t a) (d :: m)
#

Type-level foldMap.

Instances6Eval

Default implementations

Derived operations

0 declarations

Predicates

datadata And (a :: t Bool) (b :: Bool)
#

Give True if all of the booleans in the list are True.

Example
Example1 expression
:kind! Eval (And [True, True])Eval (And [True, True]) :: Bool= True
Example1 expression
:kind! Eval (And [True, True, False])Eval (And [True, True, False]) :: Bool= False
Instances1Eval
  • type Eval (And lst) = Eval (Foldr (&&) 'True lst)Defined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
datadata Or (a :: t Bool) (b :: Bool)
#

Give True if any of the booleans in the list are True.

Example
Example1 expression
:kind! Eval (Or [True, True])Eval (Or [True, True]) :: Bool= True
Example1 expression
:kind! Eval (Or [False, False])Eval (Or [False, False]) :: Bool= False
Instances1Eval
  • type Eval (Or lst) = Eval (Foldr (||) 'False lst)Defined in first-class-families-0.8.1.0 · Fcf.Class.Foldable
datadata All (b :: a -> Exp Bool) (c :: t a) (d :: Bool)
#

Whether all elements of the list satisfy a predicate.

Note: this identifier conflicts with All (from Data.Monoid).

Example
Example1 expression
:kind! Eval (All (Flip (<) 6) [0,1,2,3,4,5])Eval (All (Flip (<) 6) [0,1,2,3,4,5]) :: Bool= True
Example1 expression
:kind! Eval (All (Flip (<) 5) [0,1,2,3,4,5])Eval (All (Flip (<) 5) [0,1,2,3,4,5]) :: Bool= False
Instances1Eval
datadata Any (b :: a -> Exp Bool) (c :: t a) (d :: Bool)
#

Whether any element of the list satisfies a predicate.

Note: this identifier conflicts with Any (from Fcf.Utils), Any (from Data.Monoid), and Any (from GHC.Exts).

Example
Example1 expression
:kind! Eval (Any (Flip (<) 5) [0,1,2,3,4,5])Eval (Any (Flip (<) 5) [0,1,2,3,4,5]) :: Bool= True
Example1 expression
:kind! Eval (Any (Flip (<) 0) [0,1,2,3,4,5])Eval (Any (Flip (<) 0) [0,1,2,3,4,5]) :: Bool= False
Instances1Eval

Numbers

datadata Sum (a :: t Nat) (b :: Nat)
#

Sum a Nat-list.

Example
Example1 expression
:kind! Eval (Sum '[1,2,3])Eval (Sum '[1,2,3]) :: Natural= 6
Instances1Eval
  • type Eval (Sum ns) = Eval (Foldr (+) 0 ns)Defined in first-class-families-0.8.1.0 · Fcf.Class.Foldable

Lists

datadata Concat (a :: t m) (b :: m)
#

Concatenate a collection of elements from a monoid.

Example

For example, fold a list of lists.

Concat :: [[a]] -> Exp [a]
Example2 expressions
:kind! Eval (Concat ([[1,2], [3,4], [5,6]]))Eval (Concat ([[1,2], [3,4], [5,6]])) :: [Natural]= [1, 2, 3, 4, 5, 6]:kind! Eval (Concat ([[Int, Maybe Int], [Maybe String, Either Double Int]]))Eval (Concat ([[Int, Maybe Int], [Maybe String, Either Double Int]])) :: [*]= [Int, Maybe Int, Maybe [Char], Either Double Int]
Instances1Eval
datadata ConcatMap (c :: a -> Exp [b]) (d :: t a) (e :: [b])
#

Map a function and concatenate the results.

This is FoldMap specialized to the list monoid.

Instances1Eval