diff options
author | Hécate <hecate+gitlab@glitchbra.in> | 2020-03-20 12:42:34 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-03-22 22:38:33 -0400 |
commit | abc02b4036c2d8efe50b720d8c8103c4f1b8899a (patch) | |
tree | 294bf1586526ffce7ea8c060642d0739581103ff | |
parent | 373621f61f812accdeba39c745eb7d015430ff8e (diff) | |
download | haskell-abc02b4036c2d8efe50b720d8c8103c4f1b8899a.tar.gz |
Annotate the non-total function in Data.Foldable as such
-rw-r--r-- | libraries/base/Data/Foldable.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs index 3624a36b15..7c1fcd7ffb 100644 --- a/libraries/base/Data/Foldable.hs +++ b/libraries/base/Data/Foldable.hs @@ -215,6 +215,8 @@ class Foldable t where -- | A variant of 'foldr' that has no base case, -- and thus may only be applied to non-empty structures. -- + -- ⚠️ This function is non-total and will raise a runtime exception if the structure happens to be empty. + -- -- @'foldr1' f = 'List.foldr1' f . 'toList'@ foldr1 :: (a -> a -> a) -> t a -> a foldr1 f xs = fromMaybe (errorWithoutStackTrace "foldr1: empty structure") @@ -227,6 +229,8 @@ class Foldable t where -- | A variant of 'foldl' that has no base case, -- and thus may only be applied to non-empty structures. -- + -- ⚠️ This function is non-total and will raise a runtime exception if the structure happens to be empty. + -- -- @'foldl1' f = 'List.foldl1' f . 'toList'@ foldl1 :: (a -> a -> a) -> t a -> a foldl1 f xs = fromMaybe (errorWithoutStackTrace "foldl1: empty structure") @@ -267,6 +271,14 @@ class Foldable t where -- | The largest element of a non-empty structure. -- + -- ⚠️ This function is non-total and will raise a runtime exception if the structure happens to be empty. + -- + -- === __Examples__ + -- >>> maximum [1..10] + -- 10 + -- >>> maximum [] + -- *** Exception: Prelude.maximum: empty list + -- -- @since 4.8.0.0 maximum :: forall a . Ord a => t a -> a maximum = fromMaybe (errorWithoutStackTrace "maximum: empty structure") . @@ -274,6 +286,14 @@ class Foldable t where -- | The least element of a non-empty structure. -- + -- ⚠️ This function is non-total and will raise a runtime exception if the structure happens to be empty + -- + -- === __Examples__ + -- >>> minimum [1..10] + -- 1 + -- >>> minimum [] + -- *** Exception: Prelude.minimum: empty list + -- -- @since 4.8.0.0 minimum :: forall a . Ord a => t a -> a minimum = fromMaybe (errorWithoutStackTrace "minimum: empty structure") . |