Commit a2567e99 authored by Oleg Grenrus's avatar Oleg Grenrus Committed by Marge Bot

Correct more doctests

parent 4d1ea2c3
Pipeline #29727 failed with stages
in 424 minutes and 31 seconds
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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]
......
......@@ -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]
......
......@@ -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
......
......@@ -71,7 +71,7 @@ import GHC.Num.BigNat
infixr 8 **
-- $setup
-- >>> import GHC.Num
-- >>> import Prelude
------------------------------------------------------------------------
-- Standard numeric classes
......
......@@ -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"
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment