diff options
author | Simon Jakobi <simon.jakobi@gmail.com> | 2021-03-19 01:23:30 +0100 |
---|---|---|
committer | Simon Jakobi <simon.jakobi@gmail.com> | 2021-08-01 15:43:59 +0200 |
commit | 4e91276a0850f5377ba217f94991768bf6a9de4b (patch) | |
tree | dd42fd76a88f78f3b1ed147306cbe2e1996d0d36 | |
parent | 54d6b20192fe6fc244248c7766533a768c591bae (diff) | |
download | haskell-wip/sjakobi/genericLength-overflow-doc.tar.gz |
base: Document overflow behaviour of genericLengthwip/sjakobi/genericLength-overflow-doc
-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 |