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

Modulefirst-class-families-0.8.1.0Haskell2010

Fcf.Data.List

Lists.

See also Fcf.Class.Foldable for additional functions.

  • 39 types

Basic functions

10 declarations
datadata (++) (b :: [a]) (c :: [a]) (d :: [a])
#

List catenation.

Example
Example2 expressions
data Example where Ex :: a -> Example  -- Hide the type of examples to avoid brittleness in different GHC versions:kind! Ex (Eval ([1, 2] ++ [3, 4]) :: [Natural])Ex (Eval ([1, 2] ++ [3, 4]) :: [Natural]) :: Example= Ex [1, 2, 3, 4]
Instances1Eval
  • type Eval (xs ++ ys) = xs <> ysDefined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Head (b :: [a]) (c :: Maybe a)
#
Instances2Eval
  • type Eval (Head '[]) = 'NothingDefined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Head (a2 ': _as)) = 'Just a2Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Last (b :: [a]) (c :: Maybe a)
#
Instances3Eval
  • type Eval (Last '[a2]) = 'Just a2Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Last '[]) = 'NothingDefined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Last (a2 ': b ': as)) = Eval (Last (b ': as))Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Tail (b :: [a]) (c :: Maybe [a])
#
Instances2Eval
  • type Eval (Tail '[]) = 'NothingDefined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Tail (_a ': as)) = 'Just asDefined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Cons (b :: a) (c :: [a]) (d :: [a])
#

Append an element to a list.

Example
Example2 expressions
:kind! Eval (Cons 1 [2, 3])Eval (Cons 1 [2, 3]) :: [Natural]= [1, 2, 3]:kind! Eval (Cons Int [Char, Maybe Double])Eval (Cons Int [Char, Maybe Double]) :: [*]= [Int, Char, Maybe Double]
Instances1Eval
  • type Eval (Cons a2 as) = a2 ': asDefined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Snoc (b :: [a]) (c :: a) (d :: [a])
#

Append an element to the end of a list.

Example
Example1 expression
:kind! Eval (Snoc [1,2,3] 4)Eval (Snoc [1,2,3] 4) :: [Natural]= [1, 2, 3, 4]
Instances1Eval
  • type Eval (Snoc lst a) = Eval (lst ++ '[a])Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Cons2 (c :: (a, b)) (d :: ([a], [b])) (e :: ([a], [b]))
#

Append elements to two lists. Used in the definition of Unzip.

Instances1Eval
  • type Eval (Cons2 '(a3, b) '(as, bs)) = '(a3 ': as, b ': bs)Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Init (b :: [a]) (c :: Maybe [a])
#
Instances3Eval
  • type Eval (Init '[a2]) = 'Just '[]Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Init '[]) = 'NothingDefined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Init (a2 ': b ': as)) = Eval (Map (Cons a2) =<< Init (b ': as))Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Null (b :: [a]) (c :: Bool)
#
Instances2Eval
  • type Eval (Null '[]) = 'TrueDefined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Null (a2 ': as)) = 'FalseDefined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Length (b :: [a]) (c :: Nat)
#
Instances2Eval
  • type Eval (Length '[]) = 0Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Length (a2 ': as)) = 1 + Eval (Length as)Defined in first-class-families-0.8.1.0 · Fcf.Data.List

List transformations

3 declarations
datadata Reverse (b :: [a]) (c :: [a])
#

Reverse a list.

Example
Example1 expression
:kind! Eval (Reverse [1,2,3,4,5])Eval (Reverse [1,2,3,4,5]) :: [Natural]= [5, 4, 3, 2, 1]
Instances1Eval
  • type Eval (Reverse l) = Eval (Rev l '[])Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Intersperse (b :: a) (c :: [a]) (d :: [a])
#

Intersperse a separator between elements of a list.

Example
Example1 expression
:kind! Eval (Intersperse 0 [1,2,3,4])Eval (Intersperse 0 [1,2,3,4]) :: [Natural]= [1, 0, 2, 0, 3, 0, 4]
Instances2Eval
  • type Eval (Intersperse _1 '[]) = '[]Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Intersperse sep (x ': xs)) = x ': Eval (PrependToAll sep xs)Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Intercalate (b :: [a]) (c :: [[a]]) (d :: [a])
#

Join a list of words separated by some word.

Example
Example1 expression
:kind! Eval (Intercalate '[", "] [ '["Lorem"], '["ipsum"], '["dolor"] ])Eval (Intercalate '[", "] [ '["Lorem"], '["ipsum"], '["dolor"] ]) :: [TL.Symbol]= ["Lorem", ", ", "ipsum", ", ", "dolor"]
Instances1Eval

Reducing lists

4 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 UnList (c :: b) (d :: a -> b -> Exp b) (e :: [a]) (f :: b)
#

This is Foldr with its argument flipped.

Instances1Eval
  • type Eval (UnList y f xs) = Eval (Foldr f y xs)Defined in first-class-families-0.8.1.0 · Fcf.Data.List
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

Unfolding and building

2 declarations
datadata Unfoldr (c :: b -> Exp (Maybe (a, b))) (d :: b) (e :: [a])
#

Unfold a generator into a list.

Example
Example2 expressions
data ToThree :: Nat -> Exp (Maybe (Nat, Nat)):{type instance Eval (ToThree b) =  If (4 TL.<=? b)    Nothing    (Just '(b, b TL.+ 1)):}
Example1 expression
:kind! Eval (Unfoldr ToThree 0)Eval (Unfoldr ToThree 0) :: [Natural]= [0, 1, 2, 3]

See also the definition of Replicate.

Instances1Eval
  • type Eval (Unfoldr f c) = Eval (UnfoldrCase f (f @@ c))Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Replicate (b :: Nat) (c :: a) (d :: [a])
#

Repeat the same element in a list.

Example
Example1 expression
:kind! Eval (Replicate 4 '("ok", 2))Eval (Replicate 4 '("ok", 2)) :: [(TL.Symbol, Natural)]= ['("ok", 2), '("ok", 2), '("ok", 2), '("ok", 2)]
Instances1Eval

Sublists

7 declarations
datadata Take (b :: Nat) (c :: [a]) (d :: [a])
#

Take a prefix of fixed length.

Example
Example1 expression
:kind! Eval (Take 2 [1,2,3,4,5])Eval (Take 2 [1,2,3,4,5]) :: [Natural]= [1, 2]
Instances1Eval
  • type Eval (Take n as) = Take_ n asDefined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Drop (b :: Nat) (c :: [a]) (d :: [a])
#

Drop a prefix of fixed length, evaluate to the remaining suffix.

Example
Example1 expression
:kind! Eval (Drop 2 [1,2,3,4,5])Eval (Drop 2 [1,2,3,4,5]) :: [Natural]= [3, 4, 5]
Instances1Eval
  • type Eval (Drop n as) = Drop_ n asDefined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata TakeWhile (b :: a -> Exp Bool) (c :: [a]) (d :: [a])
#

Take the longest prefix of elements satisfying a predicate.

Example
Example1 expression
:kind! Eval (TakeWhile ((>=) 3) [1, 2, 3, 4, 5])Eval (TakeWhile ((>=) 3) [1, 2, 3, 4, 5]) :: [Natural]= [1, 2, 3]
Instances2Eval
datadata DropWhile (b :: a -> Exp Bool) (c :: [a]) (d :: [a])
#

Drop the longest prefix of elements satisfying a predicate, evaluate to the remaining suffix.

Example

:kind! Eval (DropWhile ((>=) 3) [1, 2, 3, 4, 5]) Eval (DropWhile ((>=) 3) [1, 2, 3, 4, 5]) :: [Natural] = [4, 5]

Instances2Eval
datadata Span (b :: a -> Exp Bool) (c :: [a]) (d :: ([a], [a]))
#

Span, applied to a predicate p and a list xs, returns a tuple: the first component is the longest prefix (possibly empty) of xs whose elements satisfy p; the second component is the remainder of the list.

See also TakeWhile, DropWhile, and Break.

Example
Example1 expression
:kind! Eval (Span (Flip (<) 3) [1,2,3,4,1,2])Eval (Span (Flip (<) 3) [1,2,3,4,1,2]) :: ([Natural], [Natural])= '([1, 2], [3, 4, 1, 2])
Example1 expression
:kind! Eval (Span (Flip (<) 9) [1,2,3])Eval (Span (Flip (<) 9) [1,2,3]) :: ([Natural], [Natural])= '([1, 2, 3], '[])
Example1 expression
:kind! Eval (Span (Flip (<) 0) [1,2,3])Eval (Span (Flip (<) 0) [1,2,3]) :: ([Natural], [Natural])= '( '[], [1, 2, 3])
Instances1Eval
datadata Break (b :: a -> Exp Bool) (c :: [a]) (d :: ([a], [a]))
#

Break, applied to a predicate p and a list xs, returns a tuple: the first component is the longest prefix (possibly empty) of xs whose elements do not satisfy p; the second component is the remainder of the list.

Example
Example1 expression
:kind! Eval (Break (Flip (>) 3) [1,2,3,4,1,2])Eval (Break (Flip (>) 3) [1,2,3,4,1,2]) :: ([Natural], [Natural])= '([1, 2, 3], [4, 1, 2])
Example1 expression
:kind! Eval (Break (Flip (<) 9) [1,2,3])Eval (Break (Flip (<) 9) [1,2,3]) :: ([Natural], [Natural])= '( '[], [1, 2, 3])
Example1 expression
:kind! Eval (Break (Flip (>) 9) [1,2,3])Eval (Break (Flip (>) 9) [1,2,3]) :: ([Natural], [Natural])= '([1, 2, 3], '[])
Instances1Eval
datadata Tails (b :: [a]) (c :: [[a]])
#

List of suffixes of a list.

Example
Example1 expression
:kind! Eval (Tails [0,1,2,3])Eval (Tails [0,1,2,3]) :: [[Natural]]= [[0, 1, 2, 3], [1, 2, 3], [2, 3], '[3]]
Instances2Eval
  • type Eval (Tails '[]) = '[]Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Tails (a2 ': as)) = (a2 ': as) ': Eval (Tails as)Defined in first-class-families-0.8.1.0 · Fcf.Data.List

Predicates

datadata IsPrefixOf (b :: [a]) (c :: [a]) (d :: Bool)
#

Return True when the first list is a prefix of the second.

Example
Example1 expression
:kind! Eval ([0,1,2] `IsPrefixOf` [0,1,2,3,4,5])Eval ([0,1,2] `IsPrefixOf` [0,1,2,3,4,5]) :: Bool= True
Example1 expression
:kind! Eval ([0,1,2] `IsPrefixOf` [0,1,3,2,4,5])Eval ([0,1,2] `IsPrefixOf` [0,1,3,2,4,5]) :: Bool= False
Example1 expression
:kind! Eval ('[] `IsPrefixOf` [0,1,3,2,4,5])Eval ('[] `IsPrefixOf` [0,1,3,2,4,5]) :: Bool= True
Example1 expression
:kind! Eval ([0,1,3,2,4,5] `IsPrefixOf` '[])Eval ([0,1,3,2,4,5] `IsPrefixOf` '[]) :: Bool= False
Instances1Eval
  • type Eval (IsPrefixOf xs ys) = IsPrefixOf_ xs ysDefined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata IsSuffixOf (b :: [a]) (c :: [a]) (d :: Bool)
#

Return True when the first list is a suffix of the second.

Example
Example1 expression
:kind! Eval (IsSuffixOf [3,4,5] [0,1,2,3,4,5])Eval (IsSuffixOf [3,4,5] [0,1,2,3,4,5]) :: Bool= True
Example1 expression
:kind! Eval (IsSuffixOf [3,4,5] [0,1,3,2,4,5])Eval (IsSuffixOf [3,4,5] [0,1,3,2,4,5]) :: Bool= False
Example1 expression
:kind! Eval (IsSuffixOf '[] [0,1,3,2,4,5])Eval (IsSuffixOf '[] [0,1,3,2,4,5]) :: Bool= True
Example1 expression
:kind! Eval (IsSuffixOf [0,1,3,2,4,5] '[])Eval (IsSuffixOf [0,1,3,2,4,5] '[]) :: Bool= False
Instances1Eval
datadata IsInfixOf (b :: [a]) (c :: [a]) (d :: Bool)
#

Return True when the first list is contained within the second.

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

Searching

5 declarations
datadata Elem (b :: a) (c :: [a]) (d :: Bool)
#

Return True if an element is in a list.

See also FindIndex.

Example
Example2 expressions
:kind! Eval (Elem 1 [1,2,3])Eval (Elem 1 [1,2,3]) :: Bool= True:kind! Eval (Elem 1 [2,3])Eval (Elem 1 [2,3]) :: Bool= False
Instances1Eval
datadata Lookup (a :: k) (c :: [(k, b)]) (d :: Maybe b)
#

Find an element associated with a key in an association list.

Instances1Eval
datadata Find (b :: a -> Exp Bool) (c :: [a]) (d :: Maybe a)
#

Find Just the first element satisfying a predicate, or evaluate to Nothing if no element satisfies the predicate.

Example
Example1 expression
:kind! Eval (Find (TyEq 0) [1,2,3])Eval (Find (TyEq 0) [1,2,3]) :: Maybe Natural= Nothing
Example1 expression
:kind! Eval (Find (TyEq 0) [1,2,3,0])Eval (Find (TyEq 0) [1,2,3,0]) :: Maybe Natural= Just 0
Instances2Eval
  • type Eval (Find _p '[]) = 'NothingDefined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Find p (a2 ': as)) = Eval (If (Eval (p a2)) (Pure ('Just a2)) (Find p as))Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Filter (b :: a -> Exp Bool) (c :: [a]) (d :: [a])
#

Keep all elements that satisfy a predicate, remove all that don't.

Example
Example1 expression
:kind! Eval (Filter ((>) 3) [1,2,3,0])Eval (Filter ((>) 3) [1,2,3,0]) :: [Natural]= [1, 2, 0]
Instances2Eval
  • type Eval (Filter _p '[]) = '[]Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (Filter p (a2 ': as)) = Eval (If (Eval (p a2)) ('(:) a2 <$> Filter p as) (Filter p as))Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Partition (b :: a -> Exp Bool) (c :: [a]) (d :: ([a], [a]))
#

Split a list into one where all elements satisfy a predicate, and a second where no elements satisfy it.

Example
Example1 expression
:kind! Eval (Partition ((>=) 35) [20, 30, 40, 50])Eval (Partition ((>=) 35) [20, 30, 40, 50]) :: ([Natural],                                                [Natural])= '([20, 30], [40, 50])
Instances1Eval
  • type Eval (Partition p lst) = Eval (Foldr (PartHelp p) '('[], '[]) lst)Defined in first-class-families-0.8.1.0 · Fcf.Data.List

Indexing lists

2 declarations
datadata FindIndex (b :: a -> Exp Bool) (c :: [a]) (d :: Maybe Nat)
#

Find the index of an element satisfying the predicate.

Example
Example1 expression
:kind! Eval (FindIndex ((<=) 3) [1,2,3,1,2,3])Eval (FindIndex ((<=) 3) [1,2,3,1,2,3]) :: Maybe Natural= Just 2
Example1 expression
:kind! Eval (FindIndex ((>) 0) [1,2,3,1,2,3])Eval (FindIndex ((>) 0) [1,2,3,1,2,3]) :: Maybe Natural= Nothing
Instances2Eval
datadata SetIndex (b :: Nat) (c :: a) (d :: [a]) (e :: [a])
#

Modify an element at a given index.

The list is unchanged if the index is out of bounds.

Example
Example1 expression
:kind! Eval (SetIndex 2 7 [1,2,3])Eval (SetIndex 2 7 [1,2,3]) :: [Natural]= [1, 2, 7]
Instances1Eval
  • type Eval (SetIndex n a' as) = SetIndexImpl n a' asDefined in first-class-families-0.8.1.0 · Fcf.Data.List

Zipping and unzipping

3 declarations
datadata ZipWith (d :: a -> b -> Exp c) (e :: [a]) (f :: [b]) (g :: [c])
#

Combine elements of two lists pairwise.

Example
Example1 expression
:kind! Eval (ZipWith (+) [1,2,3] [1,1,1])Eval (ZipWith (+) [1,2,3] [1,1,1]) :: [Natural]= [2, 3, 4]
Instances3Eval
  • type Eval (ZipWith _f '[] _bs) = '[]Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (ZipWith _f _as '[]) = '[]Defined in first-class-families-0.8.1.0 · Fcf.Data.List
  • type Eval (ZipWith f (a2 ': as) (b2 ': bs)) = Eval (f a2 b2) ': Eval (ZipWith f as bs)Defined in first-class-families-0.8.1.0 · Fcf.Data.List
datadata Zip (c :: [a]) (d :: [b]) (e :: [(a, b)])
#
Instances1Eval
datadata Unzip (c :: Exp [(a, b)]) (d :: ([a], [b]))
#
Instances1Eval