diff options
author | Simon Jakobi <simon.jakobi@gmail.com> | 2021-03-19 01:23:30 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-08-02 04:10:52 -0400 |
commit | 7e8c578ed9d3469d6a5c1481f9482982c42f10ea (patch) | |
tree | 60c3c170f0b4b2cd6acfe16a721007ffd56aebc4 | |
parent | 266a74528a2550a03d66f3d726d65b47df612446 (diff) | |
download | haskell-7e8c578ed9d3469d6a5c1481f9482982c42f10ea.tar.gz |
base: Document overflow behaviour of genericLength
-rw-r--r-- | libraries/base/Data/List.hs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libraries/base/Data/List.hs b/libraries/base/Data/List.hs index 2e2b1efde4..d2813bfa35 100644 --- a/libraries/base/Data/List.hs +++ b/libraries/base/Data/List.hs @@ -752,6 +752,15 @@ minimumBy cmp = fromMaybe (errorWithoutStackTrace "minimumBy: empty structure") -- 3 -- >>> genericLength [1, 2, 3] :: Float -- 3.0 +-- +-- Users should take care to pick a return type that is wide enough to contain +-- the full length of the list. If the width is insufficient, the overflow +-- behaviour will depend on the @(+)@ implementation in the selected 'Num' +-- instance. The following example overflows because the actual list length +-- of 200 lies outside of the 'Int8' range of @-128..127@. +-- +-- >>> genericLength [1..200] :: Int8 +-- -56 genericLength :: (Num i) => [a] -> i {-# NOINLINE [1] genericLength #-} genericLength [] = 0 |