:: Monoid a => [a] -> a -package:basic-prelude
base Prelude Data.Monoid GHC.Base,
hedgehog Hedgehog.Internal.Prelude,
base-compat Data.Monoid.Compat Prelude.Compat,
relude Relude.Monoid,
rio RIO.Prelude,
validity Data.Validity,
base-prelude BasePrelude,
turtle Turtle,
classy-prelude ClassyPrelude,
Cabal-syntax Distribution.Compat.Prelude Distribution.Compat.Semigroup,
universum Universum.Monoid,
ihaskell IHaskellPrelude,
terminfo System.Console.Terminfo.Base,
basement Basement.Compat.Base Basement.Imports,
numhask NumHask.Prelude,
base-compat-batteries Data.Monoid.Compat,
clash-prelude Clash.HaskellPrelude,
HaTeX Text.LaTeX.Base Text.LaTeX.Base.Class,
foundation Foundation,
ghc-lib-parser GHC.Prelude.Basic,
ghc-internal GHC.Internal.Base GHC.Internal.Data.Monoid,
dimensional Numeric.Units.Dimensional.Prelude,
rebase Rebase.Prelude,
mixed-types-num Numeric.MixedTypes.PreludeHiding,
xmonad-contrib XMonad.Config.Prime,
constrained-categories Control.Category.Constrained.Prelude Control.Category.Hask,
copilot-language Copilot.Language.Prelude,
testing-feat Test.Feat.Enumerate,
incipit-base Incipit.Base,
LambdaHack Game.LambdaHack.Core.Prelude,
cabal-install-solver Distribution.Solver.Compat.Prelude,
faktory Faktory.Prelude,
vcr Imports,
verset Verset,
yesod-paginator Yesod.Paginator.Prelude,
calligraphy Calligraphy.Prelude,
distribution-opensuse OpenSuse.Prelude OpenSuse.Prelude,
hledger-web Hledger.Web.Import,
termonad Termonad.Prelude 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!"
Concatenate a monoid after reversing its elements. Used to glue
together a series of textual chunks that have been accumulated
"backwards".
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.
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.
>>> 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.
To disable the warning about partiality put
{-# OPTIONS_GHC
-Wno-x-partial -Wno-unrecognised-warning-flags #-} at the top of
the file. To disable it throughout a package put the same options into
ghc-options section of Cabal file. To disable it in GHCi put
:set -Wno-x-partial -Wno-unrecognised-warning-flags into
~/.ghci config file. See also the
migration guide.
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.
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