:: Monoid a => [a] -> a -package:snap-core

Fold a list using the monoid. For most types, the default definition for mconcat will be used, but the function is included in the class definition so that an optimized version can be provided for specific types.
>>> mconcat ["Hello", " ", "Haskell", "!"]
"Hello Haskell!"
Fold a list using the monoid. For most types, the default definition for mconcat will be used, but the function is included in the class definition so that an optimized version can be provided for specific types.
Concatenate a monoid after reversing its elements. Used to glue together a series of textual chunks that have been accumulated "backwards".
Compose the list of ManageHooks.
concat = mconcat
List version of <>. Note that: hcat = intercalate (<>).
Warning: This is a partial function, it throws an error on empty lists. Use pattern matching, uncons or listToMaybe instead. Consider refactoring to use Data.List.NonEmpty.
Extract the last element of a list, which must be finite and non-empty. WARNING: This function is partial. Consider using unsnoc instead.

Examples

>>> last [1, 2, 3]
3
>>> last [1..]
* Hangs forever *
>>> last []
*** Exception: Prelude.last: empty list
Identical to head, namely that fails on an empty list. Useful to avoid the x-partial warning introduced in GHC 9.8.
headErr [] = error "Prelude.head: empty list"
headErr [1,2,3] = 1
Extract the first element of a list, which must be non-empty.
>>> head [1, 2, 3]
1

>>> head [1..]
1

>>> head []
*** Exception: Prelude.head: empty list
WARNING: This function is partial. You can use case-matching, uncons or listToMaybe instead.
Extract the last element of a list, which must be finite and non-empty.
>>> last [1, 2, 3]
3

>>> last [1..]
* Hangs forever *

>>> last []
*** Exception: Prelude.last: empty list
WARNING: This function is partial. You can use reverse with case-matching, uncons or listToMaybe instead.
Utility function to go from a singleton list to it's element. Wether or not the argument is a singleton list is only checked in debug builds.
Version of modes without a Data context, only to be used within cmdArgsQuote.
Version of enum without a Data context, only to be used within cmdArgsQuote.
Extract the first element of a list, which must be non-empty.
Examples
>>> head [1, 2, 3]
1
>>> head [1..]
1
>>> head []
*** Exception: Prelude.head: empty list
Extract the first element of a list, which must be non-empty.
Extract the last element of a list, which must be finite and non-empty.
Unsafe head function with descriptive error message. This function is partial and will throw an error on empty lists. It should only be used when there's a strong invariant guaranteeing the list is non-empty. Why use this instead of a total function?
  • Preserves existing type signatures and caller simplicity
  • Makes invariant violations fail fast with clear error messages
  • Avoids pushing complexity up the call chain for conditions that should never occur
  • Used specifically in getGenerators where groupBy never produces empty groups
When to use:
  • Internal functions with strong invariants
  • Performance-critical code where the invariant is guaranteed
  • When converting to total functions would complicate the entire call chain
When NOT to use:
  • Public APIs where callers might pass invalid input
  • When the input domain genuinely includes edge cases
  • When safety is more important than performance