diff options
author | Oleg Grenrus <oleg.grenrus@iki.fi> | 2020-12-28 15:04:51 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-01-10 05:36:43 -0500 |
commit | a2567e99ecda3f92c24dcdb97c098e39a33aab11 (patch) | |
tree | e6d2610830e2c89e274cec51722af8ef1a536cb9 /libraries | |
parent | 4d1ea2c3dfc75b17dbd6f16e12bf7d037c708622 (diff) | |
download | haskell-a2567e99ecda3f92c24dcdb97c098e39a33aab11.tar.gz |
Correct more doctests
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Bifoldable.hs | 1 | ||||
-rw-r--r-- | libraries/base/Data/Bifunctor.hs | 1 | ||||
-rw-r--r-- | libraries/base/Data/Foldable.hs | 4 | ||||
-rw-r--r-- | libraries/base/Data/Functor.hs | 2 | ||||
-rw-r--r-- | libraries/base/Data/Traversable.hs | 12 | ||||
-rw-r--r-- | libraries/base/GHC/Base.hs | 5 | ||||
-rw-r--r-- | libraries/base/GHC/Float.hs | 2 | ||||
-rw-r--r-- | libraries/base/GHC/List.hs | 24 | ||||
-rw-r--r-- | libraries/base/Numeric.hs | 2 |
9 files changed, 33 insertions, 20 deletions
diff --git a/libraries/base/Data/Bifoldable.hs b/libraries/base/Data/Bifoldable.hs index 977d63d3b8..5729695b72 100644 --- a/libraries/base/Data/Bifoldable.hs +++ b/libraries/base/Data/Bifoldable.hs @@ -58,6 +58,7 @@ import GHC.Generics (K1(..)) -- $setup -- >>> import Prelude -- >>> import Data.Char +-- >>> import Data.Monoid (Product (..), Sum (..)) -- >>> data BiList a b = BiList [a] [b] -- >>> instance Bifoldable BiList where bifoldr f g z (BiList as bs) = foldr f (foldr g z bs) as diff --git a/libraries/base/Data/Bifunctor.hs b/libraries/base/Data/Bifunctor.hs index 92d235da30..e8cfe05979 100644 --- a/libraries/base/Data/Bifunctor.hs +++ b/libraries/base/Data/Bifunctor.hs @@ -22,6 +22,7 @@ import GHC.Generics ( K1(..) ) -- $setup -- >>> import Prelude +-- >>> import Data.Char (toUpper) -- | A bifunctor is a type constructor that takes -- two type arguments and is a functor in /both/ arguments. That diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs index 3ca6713c0f..9460cee2eb 100644 --- a/libraries/base/Data/Foldable.hs +++ b/libraries/base/Data/Foldable.hs @@ -116,6 +116,10 @@ import GHC.Base hiding ( foldr ) import GHC.Generics import GHC.Num ( Num(..) ) +-- $setup +-- >>> import Prelude +-- >>> import Data.Monoid (Product (..), Sum (..)) + infix 4 `elem`, `notElem` -- XXX: Missing haddock feature. Links to anchors in other modules diff --git a/libraries/base/Data/Functor.hs b/libraries/base/Data/Functor.hs index e48c19e080..9689a0e798 100644 --- a/libraries/base/Data/Functor.hs +++ b/libraries/base/Data/Functor.hs @@ -25,7 +25,7 @@ -- Nothing -- (Int -> String) -> Maybe Int -> Maybe String -- -- >>> fmap show [1,2,3] -- (a -> b) -> f a -> f b --- ["1", "2", "3"] -- (Int -> String) -> [Int] -> [String] +-- ["1","2","3"] -- (Int -> String) -> [Int] -> [String] -- -- >>> fmap show [] -- (a -> b) -> f a -> f b -- [] -- (Int -> String) -> [Int] -> [String] diff --git a/libraries/base/Data/Traversable.hs b/libraries/base/Data/Traversable.hs index 152ddc31cc..4d87cec29c 100644 --- a/libraries/base/Data/Traversable.hs +++ b/libraries/base/Data/Traversable.hs @@ -167,15 +167,9 @@ class (Functor t, Foldable t) => Traversable t where -- -- ==== __Examples__ -- - -- 'mapM' is 'traverse' for 'Monad', and the following example shows - -- how 'mapM' can apply an 'IO' action to a 'List' to produce a - -- structured result. - -- - -- Basic usage: - -- - -- >>> import System.IO - -- >>> mapM (openTempFile ".") ["t1", "t2"] - -- [("./t169980-3",{handle: ./t169980-3}),("./t269980-4",{handle: ./t269980-4})] + -- 'mapM' is literally a 'traverse' with a type signature restricted + -- to 'Monad'. Its implementation may be more efficient due to additional + -- power of 'Monad'. -- mapM :: Monad m => (a -> m b) -> t a -> m (t b) {-# INLINE mapM #-} -- See Note [Inline default methods] diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs index f51ed4fa68..d4aa29f7d1 100644 --- a/libraries/base/GHC/Base.hs +++ b/libraries/base/GHC/Base.hs @@ -129,6 +129,9 @@ import {-# SOURCE #-} Data.Semigroup.Internal ( stimesDefault , stimesIdempotentMonoid ) +-- $setup +-- >>> import GHC.Num + infixr 9 . infixr 5 ++ infixl 4 <$ @@ -216,7 +219,7 @@ class Semigroup a where -- The default definition should be sufficient, but this can be -- overridden for efficiency. -- - -- >>> import Data.List.NonEmpty + -- >>> import Data.List.NonEmpty (NonEmpty (..)) -- >>> sconcat $ "Hello" :| [" ", "Haskell", "!"] -- "Hello Haskell!" sconcat :: NonEmpty a -> a diff --git a/libraries/base/GHC/Float.hs b/libraries/base/GHC/Float.hs index 10e0539c11..e25319214d 100644 --- a/libraries/base/GHC/Float.hs +++ b/libraries/base/GHC/Float.hs @@ -71,7 +71,7 @@ import GHC.Num.BigNat infixr 8 ** -- $setup --- >>> import GHC.Num +-- >>> import Prelude ------------------------------------------------------------------------ -- Standard numeric classes diff --git a/libraries/base/GHC/List.hs b/libraries/base/GHC/List.hs index dc8f95eb5b..5f6935d770 100644 --- a/libraries/base/GHC/List.hs +++ b/libraries/base/GHC/List.hs @@ -42,7 +42,15 @@ infixl 9 !! infix 4 `elem`, `notElem` -- $setup +-- >>> import GHC.Base -- >>> import Prelude (Num (..), Ord (..), Int, Double, odd, not, undefined) +-- >>> import Control.DeepSeq (force) +-- +-- -- compiled versions are uninterruptible. +-- https://gitlab.haskell.org/ghc/ghc/-/issues/367 +-- +-- >>> let or = foldr (||) False +-- >>> let and = foldr (&&) True -------------------------------------------------------------- -- List-manipulation functions @@ -506,8 +514,8 @@ match on everything past the :, which is just the tail of scanl. -- False -- >>> foldr1 (||) [False, False, True, True] -- True --- >>> foldr1 (+) [1..] --- * Hangs forever * +-- >>> force $ foldr1 (+) [1..] +-- *** Exception: stack overflow foldr1 :: (a -> a -> a) -> [a] -> a foldr1 f = go where go [x] = x @@ -593,7 +601,7 @@ remove the cause for the chain of evaluations, and all is well. -- [False,False,True,True] -- >>> scanr1 (||) [True, True, False, False] -- [True,True,False,False] --- >>> scanr1 (+) [1..] +-- >>> force $ scanr1 (+) [1..] -- * Hangs forever * scanr1 :: (a -> a -> a) -> [a] -> [a] scanr1 _ [] = [] @@ -656,9 +664,9 @@ minimum xs = foldl1' min xs -- the consumer doesn't force each iterate. See 'iterate'' for a strict -- variant of this function. -- --- >>> iterate not True +-- >>> take 10 $ iterate not True -- [True,False,True,False... --- >>> iterate (+3) 42 +-- >>> take 10 $ iterate (+3) 42 -- [42,45,48,51,54,57,60,63... {-# NOINLINE [1] iterate #-} iterate :: (a -> a) -> a -> [a] @@ -701,7 +709,7 @@ iterate'FB c f x0 = go x0 -- | 'repeat' @x@ is an infinite list, with @x@ the value of every element. -- --- >>> repeat 17 +-- >>> take 20 $ repeat 17 --[17,17,17,17,17,17,17,17,17... repeat :: a -> [a] {-# INLINE [0] repeat #-} @@ -739,9 +747,9 @@ replicate n x = take n (repeat x) -- -- >>> cycle [] -- *** Exception: Prelude.cycle: empty list --- >>> cycle [42] +-- >>> take 20 $ cycle [42] -- [42,42,42,42,42,42,42,42,42,42... --- >>> cycle [2, 5, 7] +-- >>> take 20 $ cycle [2, 5, 7] -- [2,5,7,2,5,7,2,5,7,2,5,7... cycle :: [a] -> [a] cycle [] = errorEmptyList "cycle" diff --git a/libraries/base/Numeric.hs b/libraries/base/Numeric.hs index 58004d17e8..93daae4ec3 100644 --- a/libraries/base/Numeric.hs +++ b/libraries/base/Numeric.hs @@ -72,6 +72,8 @@ import GHC.Show import Text.ParserCombinators.ReadP( ReadP, readP_to_S, pfail ) import qualified Text.Read.Lex as L +-- $setup +-- >>> import Prelude -- ----------------------------------------------------------------------------- -- Reading |