| Copyright | (c) The University of Glasgow 2001 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | stable |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Prelude
Contents
Description
The Prelude: a standard module. The Prelude is imported by default into all Haskell modules unless either there is an explicit import statement for it, or the NoImplicitPrelude extension is enabled.
Synopsis
- data Bool
- (&&) :: Bool -> Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- not :: Bool -> Bool
- otherwise :: Bool
- data Maybe a
- maybe :: b -> (a -> b) -> Maybe a -> b
- data Either a b
- either :: (a -> c) -> (b -> c) -> Either a b -> c
- data Ordering
- data Char
- type String = [Char]
- fst :: (a, b) -> a
- snd :: (a, b) -> b
- curry :: ((a, b) -> c) -> a -> b -> c
- uncurry :: (a -> b -> c) -> (a, b) -> c
- class Eq a where
- class Eq a => Ord a where
- class Enum a where
- class Bounded a where
- data Int
- data Integer
- data Float
- data Double
- type Rational = Ratio Integer
- data Word
- class Num a where
- class (Num a, Ord a) => Real a where
- class (Real a, Enum a) => Integral a where
- class Num a => Fractional a where
- class Fractional a => Floating a where
- class (Real a, Fractional a) => RealFrac a where
- class (RealFrac a, Floating a) => RealFloat a where
- subtract :: Num a => a -> a -> a
- even :: Integral a => a -> Bool
- odd :: Integral a => a -> Bool
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- (^) :: (Num a, Integral b) => a -> b -> a
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- fromIntegral :: (Integral a, Num b) => a -> b
- realToFrac :: (Real a, Fractional b) => a -> b
- class Semigroup a where
- class Semigroup a => Monoid a where
- class Functor f where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- class Functor f => Applicative f where
- class Applicative m => Monad m where
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- class Foldable t where
- class (Functor t, Foldable t) => Traversable t where
- id :: a -> a
- const :: a -> b -> a
- (.) :: (b -> c) -> (a -> b) -> a -> c
- flip :: (a -> b -> c) -> b -> a -> c
- ($) :: (a -> b) -> a -> b
- until :: (a -> Bool) -> (a -> a) -> a -> a
- asTypeOf :: a -> a -> a
- error :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => [Char] -> a
- errorWithoutStackTrace :: forall (r :: RuntimeRep). forall (a :: TYPE r). [Char] -> a
- undefined :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => a
- seq :: a -> b -> b
- ($!) :: (a -> b) -> a -> b
- map :: (a -> b) -> [a] -> [b]
- (++) :: [a] -> [a] -> [a]
- filter :: (a -> Bool) -> [a] -> [a]
- head :: [a] -> a
- last :: [a] -> a
- tail :: [a] -> [a]
- init :: [a] -> [a]
- null :: Foldable t => t a -> Bool
- length :: Foldable t => t a -> Int
- (!!) :: [a] -> Int -> a
- reverse :: [a] -> [a]
- and :: Foldable t => t Bool -> Bool
- or :: Foldable t => t Bool -> Bool
- any :: Foldable t => (a -> Bool) -> t a -> Bool
- all :: Foldable t => (a -> Bool) -> t a -> Bool
- concat :: Foldable t => t [a] -> [a]
- concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
- scanl1 :: (a -> a -> a) -> [a] -> [a]
- scanr :: (a -> b -> b) -> b -> [a] -> [b]
- scanr1 :: (a -> a -> a) -> [a] -> [a]
- iterate :: (a -> a) -> a -> [a]
- repeat :: a -> [a]
- replicate :: Int -> a -> [a]
- cycle :: [a] -> [a]
- take :: Int -> [a] -> [a]
- drop :: Int -> [a] -> [a]
- splitAt :: Int -> [a] -> ([a], [a])
- takeWhile :: (a -> Bool) -> [a] -> [a]
- dropWhile :: (a -> Bool) -> [a] -> [a]
- span :: (a -> Bool) -> [a] -> ([a], [a])
- break :: (a -> Bool) -> [a] -> ([a], [a])
- notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- lookup :: Eq a => a -> [(a, b)] -> Maybe b
- zip :: [a] -> [b] -> [(a, b)]
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
- unzip :: [(a, b)] -> ([a], [b])
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- lines :: String -> [String]
- words :: String -> [String]
- unlines :: [String] -> String
- unwords :: [String] -> String
- type ShowS = String -> String
- class Show a where
- shows :: Show a => a -> ShowS
- showChar :: Char -> ShowS
- showString :: String -> ShowS
- showParen :: Bool -> ShowS -> ShowS
- type ReadS a = String -> [(a, String)]
- class Read a where
- reads :: Read a => ReadS a
- readParen :: Bool -> ReadS a -> ReadS a
- read :: Read a => String -> a
- lex :: ReadS String
- data IO a
- putChar :: Char -> IO ()
- putStr :: String -> IO ()
- putStrLn :: String -> IO ()
- print :: Show a => a -> IO ()
- getChar :: IO Char
- getLine :: IO String
- getContents :: IO String
- interact :: (String -> String) -> IO ()
- type FilePath = String
- readFile :: FilePath -> IO String
- writeFile :: FilePath -> String -> IO ()
- appendFile :: FilePath -> String -> IO ()
- readIO :: Read a => String -> IO a
- readLn :: Read a => IO a
- type IOError = IOException
- ioError :: IOError -> IO a
- userError :: String -> IOError
Standard types, classes and related functions
Basic data types
Instances
| Bounded Bool # | Since: base-2.1 |
| Enum Bool # | Since: base-2.1 |
| Eq Bool | |
| Data Bool # | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Bool -> c Bool Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Bool Source # toConstr :: Bool -> Constr Source # dataTypeOf :: Bool -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Bool) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Bool) Source # gmapT :: (forall b. Data b => b -> b) -> Bool -> Bool Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bool -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bool -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Bool -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Bool -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Bool -> m Bool Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Bool -> m Bool Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Bool -> m Bool Source # | |
| Ord Bool | |
| Read Bool # | Since: base-2.1 |
| Show Bool # | |
| Ix Bool # | Since: base-2.1 |
| Generic Bool # | |
| FiniteBits Bool # | Since: base-4.7.0.0 |
| Bits Bool # | Interpret Since: base-4.7.0.0 |
Defined in Data.Bits Methods (.&.) :: Bool -> Bool -> Bool Source # (.|.) :: Bool -> Bool -> Bool Source # xor :: Bool -> Bool -> Bool Source # complement :: Bool -> Bool Source # shift :: Bool -> Int -> Bool Source # rotate :: Bool -> Int -> Bool Source # setBit :: Bool -> Int -> Bool Source # clearBit :: Bool -> Int -> Bool Source # complementBit :: Bool -> Int -> Bool Source # testBit :: Bool -> Int -> Bool Source # bitSizeMaybe :: Bool -> Maybe Int Source # bitSize :: Bool -> Int Source # isSigned :: Bool -> Bool Source # shiftL :: Bool -> Int -> Bool Source # unsafeShiftL :: Bool -> Int -> Bool Source # shiftR :: Bool -> Int -> Bool Source # unsafeShiftR :: Bool -> Int -> Bool Source # rotateL :: Bool -> Int -> Bool Source # | |
| Storable Bool # | Since: base-2.1 |
Defined in Foreign.Storable Methods sizeOf :: Bool -> Int Source # alignment :: Bool -> Int Source # peekElemOff :: Ptr Bool -> Int -> IO Bool Source # pokeElemOff :: Ptr Bool -> Int -> Bool -> IO () Source # peekByteOff :: Ptr b -> Int -> IO Bool Source # pokeByteOff :: Ptr b -> Int -> Bool -> IO () Source # | |
| type Rep Bool # | |
The Maybe type encapsulates an optional value. A value of type
either contains a value of type Maybe aa (represented as ),
or it is empty (represented as Just aNothing). Using Maybe is a good way to
deal with errors or exceptional cases without resorting to drastic
measures such as error.
The Maybe type is also a monad. It is a simple kind of error
monad, where all errors are represented by Nothing. A richer
error monad can be built using the Either type.
Instances
| Monad Maybe # | Since: base-2.1 |
| Functor Maybe # | Since: base-2.1 |
| MonadFix Maybe # | Since: base-2.1 |
| MonadFail Maybe # | Since: base-4.9.0.0 |
| Applicative Maybe # | Since: base-2.1 |
| Foldable Maybe # | Since: base-2.1 |
Defined in Data.Foldable Methods fold :: Monoid m => Maybe m -> m Source # foldMap :: Monoid m => (a -> m) -> Maybe a -> m Source # foldr :: (a -> b -> b) -> b -> Maybe a -> b Source # foldr' :: (a -> b -> b) -> b -> Maybe a -> b Source # foldl :: (b -> a -> b) -> b -> Maybe a -> b Source # foldl' :: (b -> a -> b) -> b -> Maybe a -> b Source # foldr1 :: (a -> a -> a) -> Maybe a -> a Source # foldl1 :: (a -> a -> a) -> Maybe a -> a Source # toList :: Maybe a -> [a] Source # null :: Maybe a -> Bool Source # length :: Maybe a -> Int Source # elem :: Eq a => a -> Maybe a -> Bool Source # maximum :: Ord a => Maybe a -> a Source # minimum :: Ord a => Maybe a -> a Source # | |
| Traversable Maybe # | Since: base-2.1 |
| MonadPlus Maybe # | Since: base-2.1 |
| Alternative Maybe # | Since: base-2.1 |
| MonadZip Maybe # | Since: base-4.8.0.0 |
| Show1 Maybe # | Since: base-4.9.0.0 |
| Read1 Maybe # | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Maybe a) Source # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Maybe a] Source # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Maybe a) Source # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Maybe a] Source # | |
| Ord1 Maybe # | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
| Eq1 Maybe # | Since: base-4.9.0.0 |
| Eq a => Eq (Maybe a) # | |
| Data a => Data (Maybe a) # | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Maybe a -> c (Maybe a) Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Maybe a) Source # toConstr :: Maybe a -> Constr Source # dataTypeOf :: Maybe a -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Maybe a)) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Maybe a)) Source # gmapT :: (forall b. Data b => b -> b) -> Maybe a -> Maybe a Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Maybe a -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Maybe a -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Maybe a -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Maybe a -> m (Maybe a) Source # | |
| Ord a => Ord (Maybe a) # | |
| Read a => Read (Maybe a) # | Since: base-2.1 |
| Show a => Show (Maybe a) # | |
| Generic (Maybe a) # | |
| Semigroup a => Semigroup (Maybe a) # | Since: base-4.9.0.0 |
| Semigroup a => Monoid (Maybe a) # | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
| Generic1 Maybe # | |
| type Rep (Maybe a) # | |
| type Rep1 Maybe # | |
maybe :: b -> (a -> b) -> Maybe a -> b Source #
The maybe function takes a default value, a function, and a Maybe
value. If the Maybe value is Nothing, the function returns the
default value. Otherwise, it applies the function to the value inside
the Just and returns the result.
Examples
Basic usage:
>>>maybe False odd (Just 3)True
>>>maybe False odd NothingFalse
Read an integer from a string using readMaybe. If we succeed,
return twice the integer; that is, apply (*2) to it. If instead
we fail to parse an integer, return 0 by default:
>>>import Text.Read ( readMaybe )>>>maybe 0 (*2) (readMaybe "5")10>>>maybe 0 (*2) (readMaybe "")0
Apply show to a Maybe Int. If we have Just n, we want to show
the underlying Int n. But if we have Nothing, we return the
empty string instead of (for example) "Nothing":
>>>maybe "" show (Just 5)"5">>>maybe "" show Nothing""
The Either type represents values with two possibilities: a value of
type is either Either a b or Left a.Right b
The Either type is sometimes used to represent a value which is
either correct or an error; by convention, the Left constructor is
used to hold an error value and the Right constructor is used to
hold a correct value (mnemonic: "right" also means "correct").
Examples
The type is the type of values which can be either
a Either String IntString or an Int. The Left constructor can be used only on
Strings, and the Right constructor can be used only on Ints:
>>>let s = Left "foo" :: Either String Int>>>sLeft "foo">>>let n = Right 3 :: Either String Int>>>nRight 3>>>:type ss :: Either String Int>>>:type nn :: Either String Int
The fmap from our Functor instance will ignore Left values, but
will apply the supplied function to values contained in a Right:
>>>let s = Left "foo" :: Either String Int>>>let n = Right 3 :: Either String Int>>>fmap (*2) sLeft "foo">>>fmap (*2) nRight 6
The Monad instance for Either allows us to chain together multiple
actions which may fail, and fail overall if any of the individual
steps failed. First we'll write a function that can either parse an
Int from a Char, or fail.
>>>import Data.Char ( digitToInt, isDigit )>>>:{let parseEither :: Char -> Either String Int parseEither c | isDigit c = Right (digitToInt c) | otherwise = Left "parse error">>>:}
The following should work, since both '1' and '2' can be
parsed as Ints.
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither '1' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleRight 3
But the following should fail overall, since the first operation where
we attempt to parse 'm' as an Int will fail:
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither 'm' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleLeft "parse error"
Instances
| Show2 Either # | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
| Read2 Either # | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes Methods liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Either a b) Source # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Either a b] Source # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Either a b) Source # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Either a b] Source # | |
| Ord2 Either # | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
| Eq2 Either # | Since: base-4.9.0.0 |
| Bifunctor Either # | Since: base-4.8.0.0 |
| Bifoldable Either # | Since: base-4.10.0.0 |
Defined in Data.Bifoldable | |
| Bitraversable Either # | Since: base-4.10.0.0 |
Defined in Data.Bitraversable Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d) Source # | |
| Monad (Either e) # | Since: base-4.4.0.0 |
| Functor (Either a) # | Since: base-3.0 |
| MonadFix (Either e) # | Since: base-4.3.0.0 |
| Applicative (Either e) # | Since: base-3.0 |
Defined in Data.Either | |
| Foldable (Either a) # | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Either a m -> m Source # foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m Source # foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b Source # foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b Source # foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b Source # foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b Source # foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source # foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source # toList :: Either a a0 -> [a0] Source # null :: Either a a0 -> Bool Source # length :: Either a a0 -> Int Source # elem :: Eq a0 => a0 -> Either a a0 -> Bool Source # maximum :: Ord a0 => Either a a0 -> a0 Source # minimum :: Ord a0 => Either a a0 -> a0 Source # | |
| Traversable (Either a) # | Since: base-4.7.0.0 |
Defined in Data.Traversable Methods traverse :: Applicative f => (a0 -> f b) -> Either a a0 -> f (Either a b) Source # sequenceA :: Applicative f => Either a (f a0) -> f (Either a a0) Source # mapM :: Monad m => (a0 -> m b) -> Either a a0 -> m (Either a b) Source # sequence :: Monad m => Either a (m a0) -> m (Either a a0) Source # | |
| Show a => Show1 (Either a) # | Since: base-4.9.0.0 |
| Read a => Read1 (Either a) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Either a a0) Source # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Either a a0] Source # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Either a a0) Source # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Either a a0] Source # | |
| Ord a => Ord1 (Either a) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
| Eq a => Eq1 (Either a) # | Since: base-4.9.0.0 |
| Generic1 (Either a :: * -> *) # | |
| (Eq a, Eq b) => Eq (Either a b) # | |
| (Data a, Data b) => Data (Either a b) # | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Either a b -> c (Either a b) Source # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Either a b) Source # toConstr :: Either a b -> Constr Source # dataTypeOf :: Either a b -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Either a b)) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Either a b)) Source # gmapT :: (forall b0. Data b0 => b0 -> b0) -> Either a b -> Either a b Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Either a b -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Either a b -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Either a b -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Either a b -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Either a b -> m (Either a b) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Either a b -> m (Either a b) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Either a b -> m (Either a b) Source # | |
| (Ord a, Ord b) => Ord (Either a b) # | |
Defined in Data.Either Methods compare :: Either a b -> Either a b -> Ordering Source # (<) :: Either a b -> Either a b -> Bool Source # (<=) :: Either a b -> Either a b -> Bool Source # (>) :: Either a b -> Either a b -> Bool Source # (>=) :: Either a b -> Either a b -> Bool Source # | |
| (Read a, Read b) => Read (Either a b) # | |
| (Show a, Show b) => Show (Either a b) # | |
| Generic (Either a b) # | |
| Semigroup (Either a b) # | Since: base-4.9.0.0 |
| type Rep1 (Either a :: * -> *) # | |
Defined in GHC.Generics type Rep1 (Either a :: * -> *) = D1 (MetaData "Either" "Data.Either" "base" False) (C1 (MetaCons "Left" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "Right" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1)) | |
| type Rep (Either a b) # | |
Defined in GHC.Generics type Rep (Either a b) = D1 (MetaData "Either" "Data.Either" "base" False) (C1 (MetaCons "Left" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "Right" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 b))) | |
either :: (a -> c) -> (b -> c) -> Either a b -> c Source #
Case analysis for the Either type.
If the value is , apply the first function to Left aa;
if it is , apply the second function to Right bb.
Examples
We create two values of type , one using the
Either String IntLeft constructor and another using the Right constructor. Then
we apply "either" the length function (if we have a String)
or the "times-two" function (if we have an Int):
>>>let s = Left "foo" :: Either String Int>>>let n = Right 3 :: Either String Int>>>either length (*2) s3>>>either length (*2) n6
Instances
The character type Char is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) code points (i.e. characters, see
http://www.unicode.org/ for details). This set extends the ISO 8859-1
(Latin-1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char.
To convert a Char to or from the corresponding Int value defined
by Unicode, use toEnum and fromEnum from the
Enum class respectively (or equivalently ord and chr).
Instances
| Bounded Char # | Since: base-2.1 |
| Enum Char # | Since: base-2.1 |
| Eq Char | |
| Data Char # | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Char -> c Char Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Char Source # toConstr :: Char -> Constr Source # dataTypeOf :: Char -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Char) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Char) Source # gmapT :: (forall b. Data b => b -> b) -> Char -> Char Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Char -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Char -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Char -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Char -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Char -> m Char Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Char -> m Char Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Char -> m Char Source # | |
| Ord Char | |
| Read Char # | Since: base-2.1 |
| Show Char # | Since: base-2.1 |
| Ix Char # | Since: base-2.1 |
| Storable Char # | Since: base-2.1 |
Defined in Foreign.Storable Methods sizeOf :: Char -> Int Source # alignment :: Char -> Int Source # peekElemOff :: Ptr Char -> Int -> IO Char Source # pokeElemOff :: Ptr Char -> Int -> Char -> IO () Source # peekByteOff :: Ptr b -> Int -> IO Char Source # pokeByteOff :: Ptr b -> Int -> Char -> IO () Source # | |
| IsChar Char # | Since: base-2.1 |
| PrintfArg Char # | Since: base-2.1 |
Defined in Text.Printf | |
| Generic1 (URec Char :: k -> *) # | |
| Functor (URec Char :: * -> *) # | |
| Foldable (URec Char :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Char m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Char a -> m Source # foldr :: (a -> b -> b) -> b -> URec Char a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Char a -> b Source # foldl :: (b -> a -> b) -> b -> URec Char a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Char a -> b Source # foldr1 :: (a -> a -> a) -> URec Char a -> a Source # foldl1 :: (a -> a -> a) -> URec Char a -> a Source # toList :: URec Char a -> [a] Source # null :: URec Char a -> Bool Source # length :: URec Char a -> Int Source # elem :: Eq a => a -> URec Char a -> Bool Source # maximum :: Ord a => URec Char a -> a Source # minimum :: Ord a => URec Char a -> a Source # | |
| Traversable (URec Char :: * -> *) # | |
Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Char a -> f (URec Char b) Source # sequenceA :: Applicative f => URec Char (f a) -> f (URec Char a) Source # mapM :: Monad m => (a -> m b) -> URec Char a -> m (URec Char b) Source # sequence :: Monad m => URec Char (m a) -> m (URec Char a) Source # | |
| Eq (URec Char p) # | |
| Ord (URec Char p) # | |
Defined in GHC.Generics Methods compare :: URec Char p -> URec Char p -> Ordering Source # (<) :: URec Char p -> URec Char p -> Bool Source # (<=) :: URec Char p -> URec Char p -> Bool Source # (>) :: URec Char p -> URec Char p -> Bool Source # (>=) :: URec Char p -> URec Char p -> Bool Source # | |
| Show (URec Char p) # | |
| Generic (URec Char p) # | |
| data URec Char (p :: k) # | Used for marking occurrences of Since: base-4.9.0.0 |
| type Rep1 (URec Char :: k -> *) # | |
Defined in GHC.Generics | |
| type Rep (URec Char p) # | |
Defined in GHC.Generics | |
Tuples
uncurry :: (a -> b -> c) -> (a, b) -> c Source #
uncurry converts a curried function to a function on pairs.
Examples
>>>uncurry (+) (1,2)3
>>>uncurry ($) (show, 1)"1"
>>>map (uncurry max) [(1,2), (3,4), (6,8)][2,4,8]
Basic type classes
The Eq class defines equality (==) and inequality (/=).
All the basic datatypes exported by the Prelude are instances of Eq,
and Eq may be derived for any datatype whose constituents are also
instances of Eq.
Instances
class Eq a => Ord a where Source #
The Ord class is used for totally ordered datatypes.
Instances of Ord can be derived for any user-defined
datatype whose constituent types are in Ord. The declared order
of the constructors in the data declaration determines the ordering
in derived Ord instances. The Ordering datatype allows a single
comparison to determine the precise ordering of two objects.
Minimal complete definition: either compare or <=.
Using compare can be more efficient for complex types.
Methods
compare :: a -> a -> Ordering Source #
(<) :: a -> a -> Bool infix 4 Source #
(<=) :: a -> a -> Bool infix 4 Source #
(>) :: a -> a -> Bool infix 4 Source #
Instances
| Ord Bool | |
| Ord Char | |
| Ord Double | |
| Ord Float | |
Defined in GHC.Classes | |
| Ord Int | |
| Ord Int8 # | Since: base-2.1 |
| Ord Int16 # | Since: base-2.1 |
Defined in GHC.Int | |
| Ord Int32 # | Since: base-2.1 |
Defined in GHC.Int | |
| Ord Int64 # | Since: base-2.1 |
Defined in GHC.Int | |
| Ord Integer | |
Defined in GHC.Integer.Type | |
| Ord Natural # | |
| Ord Ordering | |
Defined in GHC.Classes | |
| Ord Word | |
| Ord Word8 # | Since: base-2.1 |
Defined in GHC.Word | |
| Ord Word16 # | Since: base-2.1 |
| Ord Word32 # | Since: base-2.1 |
| Ord Word64 # | Since: base-2.1 |
| Ord SomeTypeRep # | |
Defined in Data.Typeable.Internal Methods compare :: SomeTypeRep -> SomeTypeRep -> Ordering Source # (<) :: SomeTypeRep -> SomeTypeRep -> Bool Source # (<=) :: SomeTypeRep -> SomeTypeRep -> Bool Source # (>) :: SomeTypeRep -> SomeTypeRep -> Bool Source # (>=) :: SomeTypeRep -> SomeTypeRep -> Bool Source # max :: SomeTypeRep -> SomeTypeRep -> SomeTypeRep Source # min :: SomeTypeRep -> SomeTypeRep -> SomeTypeRep Source # | |
| Ord () | |
| Ord TyCon | |
Defined in GHC.Classes | |
| Ord BigNat | |
| Ord GeneralCategory # | |
Defined in GHC.Unicode Methods compare :: GeneralCategory -> GeneralCategory -> Ordering Source # (<) :: GeneralCategory -> GeneralCategory -> Bool Source # (<=) :: GeneralCategory -> GeneralCategory -> Bool Source # (>) :: GeneralCategory -> GeneralCategory -> Bool Source # (>=) :: GeneralCategory -> GeneralCategory -> Bool Source # max :: GeneralCategory -> GeneralCategory -> GeneralCategory Source # min :: GeneralCategory -> GeneralCategory -> GeneralCategory Source # | |
| Ord Fingerprint # | |
Defined in GHC.Fingerprint.Type Methods compare :: Fingerprint -> Fingerprint -> Ordering Source # (<) :: Fingerprint -> Fingerprint -> Bool Source # (<=) :: Fingerprint -> Fingerprint -> Bool Source # (>) :: Fingerprint -> Fingerprint -> Bool Source # (>=) :: Fingerprint -> Fingerprint -> Bool Source # max :: Fingerprint -> Fingerprint -> Fingerprint Source # min :: Fingerprint -> Fingerprint -> Fingerprint Source # | |
| Ord IOMode # | |
| Ord IntPtr # | |
| Ord WordPtr # | |
| Ord CUIntMax # | |
Defined in Foreign.C.Types | |
| Ord CIntMax # | |
| Ord CUIntPtr # | |
Defined in Foreign.C.Types | |
| Ord CIntPtr # | |
| Ord CSUSeconds # | |
Defined in Foreign.C.Types Methods compare :: CSUSeconds -> CSUSeconds -> Ordering Source # (<) :: CSUSeconds -> CSUSeconds -> Bool Source # (<=) :: CSUSeconds -> CSUSeconds -> Bool Source # (>) :: CSUSeconds -> CSUSeconds -> Bool Source # (>=) :: CSUSeconds -> CSUSeconds -> Bool Source # max :: CSUSeconds -> CSUSeconds -> CSUSeconds Source # min :: CSUSeconds -> CSUSeconds -> CSUSeconds Source # | |
| Ord CUSeconds # | |
Defined in Foreign.C.Types | |
| Ord CTime # | |
Defined in Foreign.C.Types | |
| Ord CClock # | |
| Ord CSigAtomic # | |
Defined in Foreign.C.Types Methods compare :: CSigAtomic -> CSigAtomic -> Ordering Source # (<) :: CSigAtomic -> CSigAtomic -> Bool Source # (<=) :: CSigAtomic -> CSigAtomic -> Bool Source # (>) :: CSigAtomic -> CSigAtomic -> Bool Source # (>=) :: CSigAtomic -> CSigAtomic -> Bool Source # max :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # min :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # | |
| Ord CWchar # | |
| Ord CSize # | |
Defined in Foreign.C.Types | |
| Ord CPtrdiff # | |
Defined in Foreign.C.Types | |
| Ord CDouble # | |
| Ord CFloat # | |
| Ord CBool # | |
Defined in Foreign.C.Types | |
| Ord CULLong # | |
| Ord CLLong # | |
| Ord CULong # | |
| Ord CLong # | |
Defined in Foreign.C.Types | |
| Ord CUInt # | |
Defined in Foreign.C.Types | |
| Ord CInt # | |
| Ord CUShort # | |
| Ord CShort # | |
| Ord CUChar # | |
| Ord CSChar # | |
| Ord CChar # | |
Defined in Foreign.C.Types | |
| Ord SomeNat # | Since: base-4.7.0.0 |
| Ord SomeSymbol # | Since: base-4.7.0.0 |
Defined in GHC.TypeLits Methods compare :: SomeSymbol -> SomeSymbol -> Ordering Source # (<) :: SomeSymbol -> SomeSymbol -> Bool Source # (<=) :: SomeSymbol -> SomeSymbol -> Bool Source # (>) :: SomeSymbol -> SomeSymbol -> Bool Source # (>=) :: SomeSymbol -> SomeSymbol -> Bool Source # max :: SomeSymbol -> SomeSymbol -> SomeSymbol Source # min :: SomeSymbol -> SomeSymbol -> SomeSymbol Source # | |
| Ord DecidedStrictness # | |
Defined in GHC.Generics Methods compare :: DecidedStrictness -> DecidedStrictness -> Ordering Source # (<) :: DecidedStrictness -> DecidedStrictness -> Bool Source # (<=) :: DecidedStrictness -> DecidedStrictness -> Bool Source # (>) :: DecidedStrictness -> DecidedStrictness -> Bool Source # (>=) :: DecidedStrictness -> DecidedStrictness -> Bool Source # max :: DecidedStrictness -> DecidedStrictness -> DecidedStrictness Source # min :: DecidedStrictness -> DecidedStrictness -> DecidedStrictness Source # | |
| Ord SourceStrictness # | |
Defined in GHC.Generics Methods compare :: SourceStrictness -> SourceStrictness -> Ordering Source # (<) :: SourceStrictness -> SourceStrictness -> Bool Source # (<=) :: SourceStrictness -> SourceStrictness -> Bool Source # (>) :: SourceStrictness -> SourceStrictness -> Bool Source # (>=) :: SourceStrictness -> SourceStrictness -> Bool Source # max :: SourceStrictness -> SourceStrictness -> SourceStrictness Source # min :: SourceStrictness -> SourceStrictness -> SourceStrictness Source # | |
| Ord SourceUnpackedness # | |
Defined in GHC.Generics Methods compare :: SourceUnpackedness -> SourceUnpackedness -> Ordering Source # (<) :: SourceUnpackedness -> SourceUnpackedness -> Bool Source # (<=) :: SourceUnpackedness -> SourceUnpackedness -> Bool Source # (>) :: SourceUnpackedness -> SourceUnpackedness -> Bool Source # (>=) :: SourceUnpackedness -> SourceUnpackedness -> Bool Source # max :: SourceUnpackedness -> SourceUnpackedness -> SourceUnpackedness Source # min :: SourceUnpackedness -> SourceUnpackedness -> SourceUnpackedness Source # | |
| Ord Associativity # | |
Defined in GHC.Generics Methods compare :: Associativity -> Associativity -> Ordering Source # (<) :: Associativity -> Associativity -> Bool Source # (<=) :: Associativity -> Associativity -> Bool Source # (>) :: Associativity -> Associativity -> Bool Source # (>=) :: Associativity -> Associativity -> Bool Source # max :: Associativity -> Associativity -> Associativity Source # min :: Associativity -> Associativity -> Associativity Source # | |
| Ord Fixity # | |
| Ord Any # | |
| Ord All # | |
| Ord ArithException # | |
Defined in GHC.Exception Methods compare :: ArithException -> ArithException -> Ordering Source # (<) :: ArithException -> ArithException -> Bool Source # (<=) :: ArithException -> ArithException -> Bool Source # (>) :: ArithException -> ArithException -> Bool Source # (>=) :: ArithException -> ArithException -> Bool Source # max :: ArithException -> ArithException -> ArithException Source # min :: ArithException -> ArithException -> ArithException Source # | |
| Ord ErrorCall # | |
Defined in GHC.Exception | |
| Ord SeekMode # | |
Defined in GHC.IO.Device | |
| Ord NewlineMode # | |
Defined in GHC.IO.Handle.Types Methods compare :: NewlineMode -> NewlineMode -> Ordering Source # (<) :: NewlineMode -> NewlineMode -> Bool Source # (<=) :: NewlineMode -> NewlineMode -> Bool Source # (>) :: NewlineMode -> NewlineMode -> Bool Source # (>=) :: NewlineMode -> NewlineMode -> Bool Source # max :: NewlineMode -> NewlineMode -> NewlineMode Source # min :: NewlineMode -> NewlineMode -> NewlineMode Source # | |
| Ord Newline # | |
Defined in GHC.IO.Handle.Types | |
| Ord BufferMode # | |
Defined in GHC.IO.Handle.Types Methods compare :: BufferMode -> BufferMode -> Ordering Source # (<) :: BufferMode -> BufferMode -> Bool Source # (<=) :: BufferMode -> BufferMode -> Bool Source # (>) :: BufferMode -> BufferMode -> Bool Source # (>=) :: BufferMode -> BufferMode -> Bool Source # max :: BufferMode -> BufferMode -> BufferMode Source # min :: BufferMode -> BufferMode -> BufferMode Source # | |
| Ord ExitCode # | |
Defined in GHC.IO.Exception | |
| Ord ArrayException # | |
Defined in GHC.IO.Exception Methods compare :: ArrayException -> ArrayException -> Ordering Source # (<) :: ArrayException -> ArrayException -> Bool Source # (<=) :: ArrayException -> ArrayException -> Bool Source # (>) :: ArrayException -> ArrayException -> Bool Source # (>=) :: ArrayException -> ArrayException -> Bool Source # max :: ArrayException -> ArrayException -> ArrayException Source # min :: ArrayException -> ArrayException -> ArrayException Source # | |
| Ord AsyncException # | |
Defined in GHC.IO.Exception Methods compare :: AsyncException -> AsyncException -> Ordering Source # (<) :: AsyncException -> AsyncException -> Bool Source # (<=) :: AsyncException -> AsyncException -> Bool Source # (>) :: AsyncException -> AsyncException -> Bool Source # (>=) :: AsyncException -> AsyncException -> Bool Source # max :: AsyncException -> AsyncException -> AsyncException Source # min :: AsyncException -> AsyncException -> AsyncException Source # | |
| Ord Fd # | |
| Ord CTimer # | |
| Ord CKey # | |
| Ord CId # | |
| Ord CFsFilCnt # | |
Defined in System.Posix.Types | |
| Ord CFsBlkCnt # | |
Defined in System.Posix.Types | |
| Ord CClockId # | |
Defined in System.Posix.Types | |
| Ord CBlkCnt # | |
Defined in System.Posix.Types | |
| Ord CBlkSize # | |
Defined in System.Posix.Types | |
| Ord CRLim # | |
Defined in System.Posix.Types | |
| Ord CTcflag # | |
Defined in System.Posix.Types | |
| Ord CSpeed # | |
| Ord CCc # | |
| Ord CUid # | |
| Ord CNlink # | |
| Ord CGid # | |
| Ord CSsize # | |
| Ord CPid # | |
| Ord COff # | |
| Ord CMode # | |
Defined in System.Posix.Types | |
| Ord CIno # | |
| Ord CDev # | |
| Ord ThreadStatus # | |
Defined in GHC.Conc.Sync Methods compare :: ThreadStatus -> ThreadStatus -> Ordering Source # (<) :: ThreadStatus -> ThreadStatus -> Bool Source # (<=) :: ThreadStatus -> ThreadStatus -> Bool Source # (>) :: ThreadStatus -> ThreadStatus -> Bool Source # (>=) :: ThreadStatus -> ThreadStatus -> Bool Source # max :: ThreadStatus -> ThreadStatus -> ThreadStatus Source # min :: ThreadStatus -> ThreadStatus -> ThreadStatus Source # | |
| Ord BlockReason # | |
Defined in GHC.Conc.Sync Methods compare :: BlockReason -> BlockReason -> Ordering Source # (<) :: BlockReason -> BlockReason -> Bool Source # (<=) :: BlockReason -> BlockReason -> Bool Source # (>) :: BlockReason -> BlockReason -> Bool Source # (>=) :: BlockReason -> BlockReason -> Bool Source # max :: BlockReason -> BlockReason -> BlockReason Source # min :: BlockReason -> BlockReason -> BlockReason Source # | |
| Ord ThreadId # | Since: base-4.2.0.0 |
Defined in GHC.Conc.Sync | |
| Ord Version # | Since: base-2.1 |
| Ord ByteOrder # | |
Defined in GHC.ByteOrder | |
| Ord Unique # | |
| Ord Void # | Since: base-4.8.0.0 |
| Ord a => Ord [a] | |
| Ord a => Ord (Maybe a) # | |
| Integral a => Ord (Ratio a) # | Since: base-2.0.1 |
| Ord (Ptr a) # | |
Defined in GHC.Ptr | |
| Ord (FunPtr a) # | |
Defined in GHC.Ptr | |
| Ord p => Ord (Par1 p) # | |
| Ord a => Ord (NonEmpty a) # | |
Defined in GHC.Base Methods compare :: NonEmpty a -> NonEmpty a -> Ordering Source # (<) :: NonEmpty a -> NonEmpty a -> Bool Source # (<=) :: NonEmpty a -> NonEmpty a -> Bool Source # (>) :: NonEmpty a -> NonEmpty a -> Bool Source # (>=) :: NonEmpty a -> NonEmpty a -> Bool Source # | |
| Ord a => Ord (Down a) # | Since: base-4.6.0.0 |
| Ord a => Ord (Product a) # | |
Defined in Data.Semigroup.Internal | |
| Ord a => Ord (Sum a) # | |
Defined in Data.Semigroup.Internal | |
| Ord a => Ord (Dual a) # | |
| Ord a => Ord (Last a) # | |
| Ord a => Ord (First a) # | |
| Ord (ForeignPtr a) # | Since: base-2.1 |
Defined in GHC.ForeignPtr Methods compare :: ForeignPtr a -> ForeignPtr a -> Ordering Source # (<) :: ForeignPtr a -> ForeignPtr a -> Bool Source # (<=) :: ForeignPtr a -> ForeignPtr a -> Bool Source # (>) :: ForeignPtr a -> ForeignPtr a -> Bool Source # (>=) :: ForeignPtr a -> ForeignPtr a -> Bool Source # max :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a Source # min :: ForeignPtr a -> ForeignPtr a -> ForeignPtr a Source # | |
| Ord a => Ord (Identity a) # | |
Defined in Data.Functor.Identity Methods compare :: Identity a -> Identity a -> Ordering Source # (<) :: Identity a -> Identity a -> Bool Source # (<=) :: Identity a -> Identity a -> Bool Source # (>) :: Identity a -> Identity a -> Bool Source # (>=) :: Identity a -> Identity a -> Bool Source # | |
| Ord a => Ord (ZipList a) # | |
Defined in Control.Applicative | |
| Ord a => Ord (Option a) # | |
Defined in Data.Semigroup | |
| Ord m => Ord (WrappedMonoid m) # | |
Defined in Data.Semigroup Methods compare :: WrappedMonoid m -> WrappedMonoid m -> Ordering Source # (<) :: WrappedMonoid m -> WrappedMonoid m -> Bool Source # (<=) :: WrappedMonoid m -> WrappedMonoid m -> Bool Source # (>) :: WrappedMonoid m -> WrappedMonoid m -> Bool Source # (>=) :: WrappedMonoid m -> WrappedMonoid m -> Bool Source # max :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m Source # min :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m Source # | |
| Ord a => Ord (Last a) # | |
| Ord a => Ord (First a) # | |
| Ord a => Ord (Max a) # | |
Defined in Data.Semigroup | |
| Ord a => Ord (Min a) # | |
Defined in Data.Semigroup | |
| Ord (Fixed a) # | |
| (Ord a, Ord b) => Ord (Either a b) # | |
Defined in Data.Either Methods compare :: Either a b -> Either a b -> Ordering Source # (<) :: Either a b -> Either a b -> Bool Source # (<=) :: Either a b -> Either a b -> Bool Source # (>) :: Either a b -> Either a b -> Bool Source # (>=) :: Either a b -> Either a b -> Bool Source # | |
| Ord (V1 p) # | Since: base-4.9.0.0 |
| Ord (U1 p) # | Since: base-4.9.0.0 |
| Ord (TypeRep a) # | Since: base-4.4.0.0 |
Defined in Data.Typeable.Internal | |
| (Ord a, Ord b) => Ord (a, b) | |
| Ord (Proxy s) # | Since: base-4.7.0.0 |
| Ord a => Ord (Arg a b) # | Since: base-4.9.0.0 |
| Ord (f p) => Ord (Rec1 f p) # | |
Defined in GHC.Generics | |
| Ord (URec Word p) # | |
Defined in GHC.Generics Methods compare :: URec Word p -> URec Word p -> Ordering Source # (<) :: URec Word p -> URec Word p -> Bool Source # (<=) :: URec Word p -> URec Word p -> Bool Source # (>) :: URec Word p -> URec Word p -> Bool Source # (>=) :: URec Word p -> URec Word p -> Bool Source # | |
| Ord (URec Int p) # | |
Defined in GHC.Generics Methods compare :: URec Int p -> URec Int p -> Ordering Source # (<) :: URec Int p -> URec Int p -> Bool Source # (<=) :: URec Int p -> URec Int p -> Bool Source # (>) :: URec Int p -> URec Int p -> Bool Source # (>=) :: URec Int p -> URec Int p -> Bool Source # | |
| Ord (URec Float p) # | |
Defined in GHC.Generics Methods compare :: URec Float p -> URec Float p -> Ordering Source # (<) :: URec Float p -> URec Float p -> Bool Source # (<=) :: URec Float p -> URec Float p -> Bool Source # (>) :: URec Float p -> URec Float p -> Bool Source # (>=) :: URec Float p -> URec Float p -> Bool Source # max :: URec Float p -> URec Float p -> URec Float p Source # min :: URec Float p -> URec Float p -> URec Float p Source # | |
| Ord (URec Double p) # | |
Defined in GHC.Generics Methods compare :: URec Double p -> URec Double p -> Ordering Source # (<) :: URec Double p -> URec Double p -> Bool Source # (<=) :: URec Double p -> URec Double p -> Bool Source # (>) :: URec Double p -> URec Double p -> Bool Source # (>=) :: URec Double p -> URec Double p -> Bool Source # max :: URec Double p -> URec Double p -> URec Double p Source # min :: URec Double p -> URec Double p -> URec Double p Source # | |
| Ord (URec Char p) # | |
Defined in GHC.Generics Methods compare :: URec Char p -> URec Char p -> Ordering Source # (<) :: URec Char p -> URec Char p -> Bool Source # (<=) :: URec Char p -> URec Char p -> Bool Source # (>) :: URec Char p -> URec Char p -> Bool Source # (>=) :: URec Char p -> URec Char p -> Bool Source # | |
| Ord (URec (Ptr ()) p) # | |
Defined in GHC.Generics Methods compare :: URec (Ptr ()) p -> URec (Ptr ()) p -> Ordering Source # (<) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool Source # (<=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool Source # (>) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool Source # (>=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool Source # max :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p Source # min :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p Source # | |
| (Ord a, Ord b, Ord c) => Ord (a, b, c) | |
Defined in GHC.Classes | |
| Ord (a :~: b) # | |
Defined in Data.Type.Equality | |
| Ord (Coercion a b) # | |
Defined in Data.Type.Coercion Methods compare :: Coercion a b -> Coercion a b -> Ordering Source # (<) :: Coercion a b -> Coercion a b -> Bool Source # (<=) :: Coercion a b -> Coercion a b -> Bool Source # (>) :: Coercion a b -> Coercion a b -> Bool Source # (>=) :: Coercion a b -> Coercion a b -> Bool Source # max :: Coercion a b -> Coercion a b -> Coercion a b Source # min :: Coercion a b -> Coercion a b -> Coercion a b Source # | |
| Ord (f a) => Ord (Alt f a) # | |
Defined in Data.Semigroup.Internal | |
| Ord a => Ord (Const a b) # | |
Defined in Data.Functor.Const | |
| Ord c => Ord (K1 i c p) # | |
Defined in GHC.Generics | |
| (Ord (f p), Ord (g p)) => Ord ((f :+: g) p) # | |
Defined in GHC.Generics Methods compare :: (f :+: g) p -> (f :+: g) p -> Ordering Source # (<) :: (f :+: g) p -> (f :+: g) p -> Bool Source # (<=) :: (f :+: g) p -> (f :+: g) p -> Bool Source # (>) :: (f :+: g) p -> (f :+: g) p -> Bool Source # (>=) :: (f :+: g) p -> (f :+: g) p -> Bool Source # | |
| (Ord (f p), Ord (g p)) => Ord ((f :*: g) p) # | |
Defined in GHC.Generics Methods compare :: (f :*: g) p -> (f :*: g) p -> Ordering Source # (<) :: (f :*: g) p -> (f :*: g) p -> Bool Source # (<=) :: (f :*: g) p -> (f :*: g) p -> Bool Source # (>) :: (f :*: g) p -> (f :*: g) p -> Bool Source # (>=) :: (f :*: g) p -> (f :*: g) p -> Bool Source # | |
| (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d) -> (a, b, c, d) -> Ordering Source # (<) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source # (<=) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source # (>) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source # (>=) :: (a, b, c, d) -> (a, b, c, d) -> Bool Source # max :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source # min :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source # | |
| Ord (a :~~: b) # | Since: base-4.10.0.0 |
Defined in Data.Type.Equality Methods compare :: (a :~~: b) -> (a :~~: b) -> Ordering Source # (<) :: (a :~~: b) -> (a :~~: b) -> Bool Source # (<=) :: (a :~~: b) -> (a :~~: b) -> Bool Source # (>) :: (a :~~: b) -> (a :~~: b) -> Bool Source # (>=) :: (a :~~: b) -> (a :~~: b) -> Bool Source # | |
| (Ord1 f, Ord1 g, Ord a) => Ord (Sum f g a) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Sum | |
| (Ord1 f, Ord1 g, Ord a) => Ord (Product f g a) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Product Methods compare :: Product f g a -> Product f g a -> Ordering Source # (<) :: Product f g a -> Product f g a -> Bool Source # (<=) :: Product f g a -> Product f g a -> Bool Source # (>) :: Product f g a -> Product f g a -> Bool Source # (>=) :: Product f g a -> Product f g a -> Bool Source # max :: Product f g a -> Product f g a -> Product f g a Source # min :: Product f g a -> Product f g a -> Product f g a Source # | |
| Ord (f p) => Ord (M1 i c f p) # | |
Defined in GHC.Generics Methods compare :: M1 i c f p -> M1 i c f p -> Ordering Source # (<) :: M1 i c f p -> M1 i c f p -> Bool Source # (<=) :: M1 i c f p -> M1 i c f p -> Bool Source # (>) :: M1 i c f p -> M1 i c f p -> Bool Source # (>=) :: M1 i c f p -> M1 i c f p -> Bool Source # | |
| Ord (f (g p)) => Ord ((f :.: g) p) # | |
Defined in GHC.Generics Methods compare :: (f :.: g) p -> (f :.: g) p -> Ordering Source # (<) :: (f :.: g) p -> (f :.: g) p -> Bool Source # (<=) :: (f :.: g) p -> (f :.: g) p -> Bool Source # (>) :: (f :.: g) p -> (f :.: g) p -> Bool Source # (>=) :: (f :.: g) p -> (f :.: g) p -> Bool Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e) -> (a, b, c, d, e) -> Ordering Source # (<) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source # (<=) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source # (>) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source # (>=) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool Source # max :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source # min :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source # | |
| (Ord1 f, Ord1 g, Ord a) => Ord (Compose f g a) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose Methods compare :: Compose f g a -> Compose f g a -> Ordering Source # (<) :: Compose f g a -> Compose f g a -> Bool Source # (<=) :: Compose f g a -> Compose f g a -> Bool Source # (>) :: Compose f g a -> Compose f g a -> Bool Source # (>=) :: Compose f g a -> Compose f g a -> Bool Source # max :: Compose f g a -> Compose f g a -> Compose f g a Source # min :: Compose f g a -> Compose f g a -> Compose f g a Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Ordering Source # (<) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source # (<=) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source # (>) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source # (>=) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool Source # max :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source # min :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Ordering Source # (<) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source # (<=) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source # (>) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source # (>=) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool Source # max :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source # min :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool Source # max :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source # min :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool Source # max :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) Source # min :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord (a, b, c, d, e, f, g, h, i, j) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool Source # max :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) Source # min :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord (a, b, c, d, e, f, g, h, i, j, k) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool Source # max :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) Source # min :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord (a, b, c, d, e, f, g, h, i, j, k, l) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> Bool Source # max :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) Source # min :: (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) -> (a, b, c, d, e, f, g, h, i, j, k, l) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Bool Source # max :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # min :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Bool Source # max :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # min :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # | |
| (Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | |
Defined in GHC.Classes Methods compare :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Ordering Source # (<) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source # (<=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source # (>) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source # (>=) :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Bool Source # max :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # min :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # | |
Class Enum defines operations on sequentially ordered types.
The enumFrom... methods are used in Haskell's translation of
arithmetic sequences.
Instances of Enum may be derived for any enumeration type (types
whose constructors have no fields). The nullary constructors are
assumed to be numbered left-to-right by fromEnum from 0 through n-1.
See Chapter 10 of the Haskell Report for more details.
For any type that is an instance of class Bounded as well as Enum,
the following should hold:
- The calls
andsuccmaxBoundshould result in a runtime error.predminBound fromEnumandtoEnumshould give a runtime error if the result value is not representable in the result type. For example,is an error.toEnum7 ::BoolenumFromandenumFromThenshould be defined with an implicit bound, thus:
enumFrom x = enumFromTo x maxBound
enumFromThen x y = enumFromThenTo x y bound
where
bound | fromEnum y >= fromEnum x = maxBound
| otherwise = minBoundMethods
the successor of a value. For numeric types, succ adds 1.
the predecessor of a value. For numeric types, pred subtracts 1.
Convert from an Int.
Convert to an Int.
It is implementation-dependent what fromEnum returns when
applied to a value that is too large to fit in an Int.
Used in Haskell's translation of [n..].
enumFromThen :: a -> a -> [a] Source #
Used in Haskell's translation of [n,n'..].
enumFromTo :: a -> a -> [a] Source #
Used in Haskell's translation of [n..m].
enumFromThenTo :: a -> a -> a -> [a] Source #
Used in Haskell's translation of [n,n'..m].
Instances
class Bounded a where Source #
The Bounded class is used to name the upper and lower limits of a
type. Ord is not a superclass of Bounded since types that are not
totally ordered may also have upper and lower bounds.
The Bounded class may be derived for any enumeration type;
minBound is the first constructor listed in the data declaration
and maxBound is the last.
Bounded may also be derived for single-constructor datatypes whose
constituent types are in Bounded.
Instances
Numbers
Numeric types
A fixed-precision integer type with at least the range [-2^29 .. 2^29-1].
The exact range for a given implementation can be determined by using
minBound and maxBound from the Bounded class.
Instances
| Bounded Int # | Since: base-2.1 |
| Enum Int # | Since: base-2.1 |
Defined in GHC.Enum | |
| Eq Int | |
| Integral Int # | Since: base-2.0.1 |
| Data Int # | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Int -> c Int Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Int Source # toConstr :: Int -> Constr Source # dataTypeOf :: Int -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Int) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Int) Source # gmapT :: (forall b. Data b => b -> b) -> Int -> Int Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Int -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Int -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Int -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Int -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Int -> m Int Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Int -> m Int Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Int -> m Int Source # | |
| Num Int # | Since: base-2.1 |
| Ord Int | |
| Read Int # | Since: base-2.1 |
| Real Int # | Since: base-2.0.1 |
| Show Int # | Since: base-2.1 |
| Ix Int # | Since: base-2.1 |
| FiniteBits Int # | Since: base-4.6.0.0 |
| Bits Int # | Since: base-2.1 |
Defined in Data.Bits Methods (.&.) :: Int -> Int -> Int Source # (.|.) :: Int -> Int -> Int Source # xor :: Int -> Int -> Int Source # complement :: Int -> Int Source # shift :: Int -> Int -> Int Source # rotate :: Int -> Int -> Int Source # setBit :: Int -> Int -> Int Source # clearBit :: Int -> Int -> Int Source # complementBit :: Int -> Int -> Int Source # testBit :: Int -> Int -> Bool Source # bitSizeMaybe :: Int -> Maybe Int Source # bitSize :: Int -> Int Source # isSigned :: Int -> Bool Source # shiftL :: Int -> Int -> Int Source # unsafeShiftL :: Int -> Int -> Int Source # shiftR :: Int -> Int -> Int Source # unsafeShiftR :: Int -> Int -> Int Source # rotateL :: Int -> Int -> Int Source # | |
| Storable Int # | Since: base-2.1 |
Defined in Foreign.Storable | |
| PrintfArg Int # | Since: base-2.1 |
Defined in Text.Printf | |
| Generic1 (URec Int :: k -> *) # | |
| Functor (URec Int :: * -> *) # | |
| Foldable (URec Int :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Int m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Int a -> m Source # foldr :: (a -> b -> b) -> b -> URec Int a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Int a -> b Source # foldl :: (b -> a -> b) -> b -> URec Int a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Int a -> b Source # foldr1 :: (a -> a -> a) -> URec Int a -> a Source # foldl1 :: (a -> a -> a) -> URec Int a -> a Source # toList :: URec Int a -> [a] Source # null :: URec Int a -> Bool Source # length :: URec Int a -> Int Source # elem :: Eq a => a -> URec Int a -> Bool Source # maximum :: Ord a => URec Int a -> a Source # minimum :: Ord a => URec Int a -> a Source # | |
| Traversable (URec Int :: * -> *) # | |
Defined in Data.Traversable | |
| Eq (URec Int p) # | |
| Ord (URec Int p) # | |
Defined in GHC.Generics Methods compare :: URec Int p -> URec Int p -> Ordering Source # (<) :: URec Int p -> URec Int p -> Bool Source # (<=) :: URec Int p -> URec Int p -> Bool Source # (>) :: URec Int p -> URec Int p -> Bool Source # (>=) :: URec Int p -> URec Int p -> Bool Source # | |
| Show (URec Int p) # | |
| Generic (URec Int p) # | |
| data URec Int (p :: k) # | Used for marking occurrences of Since: base-4.9.0.0 |
| type Rep1 (URec Int :: k -> *) # | |
Defined in GHC.Generics | |
| type Rep (URec Int p) # | |
Defined in GHC.Generics | |
Invariant: Jn# and Jp# are used iff value doesn't fit in S#
Useful properties resulting from the invariants:
Instances
Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.
Instances
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
Instances
Instances
| Bounded Word # | Since: base-2.1 |
| Enum Word # | Since: base-2.1 |
| Eq Word | |
| Integral Word # | Since: base-2.1 |
Defined in GHC.Real | |
| Data Word # | Since: base-4.0.0.0 |
Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word -> c Word Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word Source # toConstr :: Word -> Constr Source # dataTypeOf :: Word -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word) Source # gmapT :: (forall b. Data b => b -> b) -> Word -> Word Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Word -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word -> m Word Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word -> m Word Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word -> m Word Source # | |
| Num Word # | Since: base-2.1 |
| Ord Word | |
| Read Word # | Since: base-4.5.0.0 |
| Real Word # | Since: base-2.1 |
| Show Word # | Since: base-2.1 |
| Ix Word # | Since: base-4.6.0.0 |
| FiniteBits Word # | Since: base-4.6.0.0 |
| Bits Word # | Since: base-2.1 |
Defined in Data.Bits Methods (.&.) :: Word -> Word -> Word Source # (.|.) :: Word -> Word -> Word Source # xor :: Word -> Word -> Word Source # complement :: Word -> Word Source # shift :: Word -> Int -> Word Source # rotate :: Word -> Int -> Word Source # setBit :: Word -> Int -> Word Source # clearBit :: Word -> Int -> Word Source # complementBit :: Word -> Int -> Word Source # testBit :: Word -> Int -> Bool Source # bitSizeMaybe :: Word -> Maybe Int Source # bitSize :: Word -> Int Source # isSigned :: Word -> Bool Source # shiftL :: Word -> Int -> Word Source # unsafeShiftL :: Word -> Int -> Word Source # shiftR :: Word -> Int -> Word Source # unsafeShiftR :: Word -> Int -> Word Source # rotateL :: Word -> Int -> Word Source # | |
| Storable Word # | Since: base-2.1 |
Defined in Foreign.Storable Methods sizeOf :: Word -> Int Source # alignment :: Word -> Int Source # peekElemOff :: Ptr Word -> Int -> IO Word Source # pokeElemOff :: Ptr Word -> Int -> Word -> IO () Source # peekByteOff :: Ptr b -> Int -> IO Word Source # pokeByteOff :: Ptr b -> Int -> Word -> IO () Source # | |
| PrintfArg Word # | Since: base-2.1 |
Defined in Text.Printf | |
| Generic1 (URec Word :: k -> *) # | |
| Functor (URec Word :: * -> *) # | |
| Foldable (URec Word :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Word m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Word a -> m Source # foldr :: (a -> b -> b) -> b -> URec Word a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Word a -> b Source # foldl :: (b -> a -> b) -> b -> URec Word a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Word a -> b Source # foldr1 :: (a -> a -> a) -> URec Word a -> a Source # foldl1 :: (a -> a -> a) -> URec Word a -> a Source # toList :: URec Word a -> [a] Source # null :: URec Word a -> Bool Source # length :: URec Word a -> Int Source # elem :: Eq a => a -> URec Word a -> Bool Source # maximum :: Ord a => URec Word a -> a Source # minimum :: Ord a => URec Word a -> a Source # | |
| Traversable (URec Word :: * -> *) # | |
Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Word a -> f (URec Word b) Source # sequenceA :: Applicative f => URec Word (f a) -> f (URec Word a) Source # mapM :: Monad m => (a -> m b) -> URec Word a -> m (URec Word b) Source # sequence :: Monad m => URec Word (m a) -> m (URec Word a) Source # | |
| Eq (URec Word p) # | |
| Ord (URec Word p) # | |
Defined in GHC.Generics Methods compare :: URec Word p -> URec Word p -> Ordering Source # (<) :: URec Word p -> URec Word p -> Bool Source # (<=) :: URec Word p -> URec Word p -> Bool Source # (>) :: URec Word p -> URec Word p -> Bool Source # (>=) :: URec Word p -> URec Word p -> Bool Source # | |
| Show (URec Word p) # | |
| Generic (URec Word p) # | |
| data URec Word (p :: k) # | Used for marking occurrences of Since: base-4.9.0.0 |
| type Rep1 (URec Word :: k -> *) # | |
Defined in GHC.Generics | |
| type Rep (URec Word p) # | |
Defined in GHC.Generics | |
Numeric type classes
Basic numeric class.
Methods
(+) :: a -> a -> a infixl 6 Source #
(-) :: a -> a -> a infixl 6 Source #
(*) :: a -> a -> a infixl 7 Source #
Unary negation.
Absolute value.
Sign of a number.
The functions abs and signum should satisfy the law:
abs x * signum x == x
For real numbers, the signum is either -1 (negative), 0 (zero)
or 1 (positive).
fromInteger :: Integer -> a Source #
Conversion from an Integer.
An integer literal represents the application of the function
fromInteger to the appropriate value of type Integer,
so such literals have type (.Num a) => a
Instances
class (Num a, Ord a) => Real a where Source #
Minimal complete definition
Methods
toRational :: a -> Rational Source #
the rational equivalent of its real argument with full precision
Instances
class (Real a, Enum a) => Integral a where Source #
Integral numbers, supporting integer division.
Methods
quot :: a -> a -> a infixl 7 Source #
integer division truncated toward zero
rem :: a -> a -> a infixl 7 Source #
integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
div :: a -> a -> a infixl 7 Source #
integer division truncated toward negative infinity
mod :: a -> a -> a infixl 7 Source #
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
quotRem :: a -> a -> (a, a) Source #
divMod :: a -> a -> (a, a) Source #
toInteger :: a -> Integer Source #
conversion to Integer
Instances
class Num a => Fractional a where Source #
Fractional numbers, supporting real division.
Minimal complete definition
fromRational, (recip | (/))
Methods
(/) :: a -> a -> a infixl 7 Source #
fractional division
reciprocal fraction
fromRational :: Rational -> a Source #
Conversion from a Rational (that is ).
A floating literal stands for an application of Ratio IntegerfromRational
to a value of type Rational, so such literals have type
(.Fractional a) => a
Instances
| Fractional Double # | Since: base-2.1 |
| Fractional Float # | Since: base-2.1 |
| Fractional CDouble # | |
| Fractional CFloat # | |
| Integral a => Fractional (Ratio a) # | Since: base-2.0.1 |
| Fractional a => Fractional (Identity a) # | |
| HasResolution a => Fractional (Fixed a) # | Since: base-2.1 |
| RealFloat a => Fractional (Complex a) # | Since: base-2.1 |
| Fractional a => Fractional (Const a b) # | |
class Fractional a => Floating a where Source #
Trigonometric and hyperbolic functions and related functions.
Minimal complete definition
pi, exp, log, sin, cos, asin, acos, atan, sinh, cosh, asinh, acosh, atanh
Instances
class (Real a, Fractional a) => RealFrac a where Source #
Extracting components of fractions.
Minimal complete definition
Methods
properFraction :: Integral b => a -> (b, a) Source #
The function properFraction takes a real fractional number x
and returns a pair (n,f) such that x = n+f, and:
nis an integral number with the same sign asx; andfis a fraction with the same type and sign asx, and with absolute value less than1.
The default definitions of the ceiling, floor, truncate
and round functions are in terms of properFraction.
truncate :: Integral b => a -> b Source #
returns the integer nearest truncate xx between zero and x
round :: Integral b => a -> b Source #
returns the nearest integer to round xx;
the even integer if x is equidistant between two integers
ceiling :: Integral b => a -> b Source #
returns the least integer not less than ceiling xx
floor :: Integral b => a -> b Source #
returns the greatest integer not greater than floor xx
Instances
| RealFrac Double # | Since: base-2.1 |
| RealFrac Float # | Since: base-2.1 |
| RealFrac CDouble # | |
| RealFrac CFloat # | |
| Integral a => RealFrac (Ratio a) # | Since: base-2.0.1 |
| RealFrac a => RealFrac (Identity a) # | |
Defined in Data.Functor.Identity | |
| HasResolution a => RealFrac (Fixed a) # | Since: base-2.1 |
| RealFrac a => RealFrac (Const a b) # | |
Defined in Data.Functor.Const | |
class (RealFrac a, Floating a) => RealFloat a where Source #
Efficient, machine-independent access to the components of a floating-point number.
Minimal complete definition
floatRadix, floatDigits, floatRange, decodeFloat, encodeFloat, isNaN, isInfinite, isDenormalized, isNegativeZero, isIEEE
Methods
floatRadix :: a -> Integer Source #
a constant function, returning the radix of the representation
(often 2)
floatDigits :: a -> Int Source #
a constant function, returning the number of digits of
floatRadix in the significand
floatRange :: a -> (Int, Int) Source #
a constant function, returning the lowest and highest values the exponent may assume
decodeFloat :: a -> (Integer, Int) Source #
The function decodeFloat applied to a real floating-point
number returns the significand expressed as an Integer and an
appropriately scaled exponent (an Int). If
yields decodeFloat x(m,n), then x is equal in value to m*b^^n, where b
is the floating-point radix, and furthermore, either m and n
are both zero or else b^(d-1) <= , where abs m < b^dd is
the value of .
In particular, floatDigits x. If the type
contains a negative zero, also decodeFloat 0 = (0,0).
The result of decodeFloat (-0.0) = (0,0) is unspecified if either of
decodeFloat x or isNaN x is isInfinite xTrue.
encodeFloat :: Integer -> Int -> a Source #
encodeFloat performs the inverse of decodeFloat in the
sense that for finite x with the exception of -0.0,
.
uncurry encodeFloat (decodeFloat x) = x is one of the two closest representable
floating-point numbers to encodeFloat m nm*b^^n (or ±Infinity if overflow
occurs); usually the closer, but if m contains too many bits,
the result may be rounded in the wrong direction.
exponent corresponds to the second component of decodeFloat.
and for finite nonzero exponent 0 = 0x,
.
If exponent x = snd (decodeFloat x) + floatDigits xx is a finite floating-point number, it is equal in value to
, where significand x * b ^^ exponent xb is the
floating-point radix.
The behaviour is unspecified on infinite or NaN values.
significand :: a -> a Source #
The first component of decodeFloat, scaled to lie in the open
interval (-1,1), either 0.0 or of absolute value >= 1/b,
where b is the floating-point radix.
The behaviour is unspecified on infinite or NaN values.
scaleFloat :: Int -> a -> a Source #
multiplies a floating-point number by an integer power of the radix
True if the argument is an IEEE "not-a-number" (NaN) value
isInfinite :: a -> Bool Source #
True if the argument is an IEEE infinity or negative infinity
isDenormalized :: a -> Bool Source #
True if the argument is too small to be represented in
normalized format
isNegativeZero :: a -> Bool Source #
True if the argument is an IEEE negative zero
True if the argument is an IEEE floating point number
a version of arctangent taking two real floating-point arguments.
For real floating x and y, computes the angle
(from the positive x-axis) of the vector from the origin to the
point atan2 y x(x,y). returns a value in the range [atan2 y x-pi,
pi]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported. , with atan2 y 1y in a type
that is RealFloat, should return the same value as .
A default definition of atan yatan2 is provided, but implementors
can provide a more accurate implementation.
Instances
Numeric functions
gcd :: Integral a => a -> a -> a Source #
is the non-negative factor of both gcd x yx and y of which
every common factor of x and y is also a factor; for example
, gcd 4 2 = 2, gcd (-4) 6 = 2 = gcd 0 44. = gcd 0 00.
(That is, the common divisor that is "greatest" in the divisibility
preordering.)
Note: Since for signed fixed-width integer types, ,
the result may be negative if one of the arguments is abs minBound < 0 (and
necessarily is if the other is minBound0 or ) for such types.minBound
lcm :: Integral a => a -> a -> a Source #
is the smallest positive integer that both lcm x yx and y divide.
(^) :: (Num a, Integral b) => a -> b -> a infixr 8 Source #
raise a number to a non-negative integral power
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 Source #
raise a number to an integral power
fromIntegral :: (Integral a, Num b) => a -> b Source #
general coercion from integral types
realToFrac :: (Real a, Fractional b) => a -> b Source #
general coercion to fractional types
Semigroups and Monoids
class Semigroup a where Source #
The class of semigroups (types with an associative binary operation).
Instances should satisfy the associativity law:
Since: base-4.9.0.0
Minimal complete definition
Instances
| Semigroup Ordering # | Since: base-4.9.0.0 |
| Semigroup () # | Since: base-4.9.0.0 |
| Semigroup Any # | Since: base-4.9.0.0 |
| Semigroup All # | Since: base-4.9.0.0 |
| Semigroup Lifetime # | Since: base-4.10.0.0 |
| Semigroup Event # | Since: base-4.10.0.0 |
| Semigroup Void # | Since: base-4.9.0.0 |
| Semigroup [a] # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Maybe a) # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (IO a) # | Since: base-4.10.0.0 |
| Semigroup (NonEmpty a) # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Down a) # | Since: base-4.11.0.0 |
| Num a => Semigroup (Product a) # | Since: base-4.9.0.0 |
| Num a => Semigroup (Sum a) # | Since: base-4.9.0.0 |
| Semigroup (Endo a) # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Dual a) # | Since: base-4.9.0.0 |
| Semigroup (Last a) # | Since: base-4.9.0.0 |
| Semigroup (First a) # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Identity a) # | |
| Semigroup a => Semigroup (Option a) # | Since: base-4.9.0.0 |
| Monoid m => Semigroup (WrappedMonoid m) # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods (<>) :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m Source # sconcat :: NonEmpty (WrappedMonoid m) -> WrappedMonoid m Source # stimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m Source # | |
| Semigroup (Last a) # | Since: base-4.9.0.0 |
| Semigroup (First a) # | Since: base-4.9.0.0 |
| Ord a => Semigroup (Max a) # | Since: base-4.9.0.0 |
| Ord a => Semigroup (Min a) # | Since: base-4.9.0.0 |
| Semigroup b => Semigroup (a -> b) # | Since: base-4.9.0.0 |
| Semigroup (Either a b) # | Since: base-4.9.0.0 |
| (Semigroup a, Semigroup b) => Semigroup (a, b) # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (ST s a) # | Since: base-4.11.0.0 |
| Semigroup (Proxy s) # | Since: base-4.9.0.0 |
| (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) # | Since: base-4.9.0.0 |
| Alternative f => Semigroup (Alt f a) # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Const a b) # | |
| (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) # | Since: base-4.9.0.0 |
| (Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) # | Since: base-4.9.0.0 |
class Semigroup a => Monoid a where Source #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:
x
<>mempty= xmempty<>x = xx(<>(y<>z) = (x<>y)<>zSemigrouplaw)mconcat=foldr'(<>)'mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtypes and make those instances
of Monoid, e.g. Sum and Product.
NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
Minimal complete definition
Methods
Identity of mappend
mappend :: a -> a -> a Source #
An associative operation
NOTE: This method is redundant and has the default
implementation since base-4.11.0.0.mappend = '(<>)'
Fold a list using the monoid.
For most types, the default definition for mconcat will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
Instances
| Monoid Ordering # | Since: base-2.1 |
| Monoid () # | Since: base-2.1 |
| Monoid Any # | Since: base-2.1 |
| Monoid All # | Since: base-2.1 |
| Monoid Lifetime # |
Since: base-4.8.0.0 |
| Monoid Event # | Since: base-4.3.1.0 |
| Monoid [a] # | Since: base-2.1 |
| Semigroup a => Monoid (Maybe a) # | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
| Monoid a => Monoid (IO a) # | Since: base-4.9.0.0 |
| Monoid a => Monoid (Down a) # | Since: base-4.11.0.0 |
| Num a => Monoid (Product a) # | Since: base-2.1 |
| Num a => Monoid (Sum a) # | Since: base-2.1 |
| Monoid (Endo a) # | Since: base-2.1 |
| Monoid a => Monoid (Dual a) # | Since: base-2.1 |
| Monoid (Last a) # | Since: base-2.1 |
| Monoid (First a) # | Since: base-2.1 |
| Monoid a => Monoid (Identity a) # | |
| Semigroup a => Monoid (Option a) # | Since: base-4.9.0.0 |
| Monoid m => Monoid (WrappedMonoid m) # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods mempty :: WrappedMonoid m Source # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m Source # mconcat :: [WrappedMonoid m] -> WrappedMonoid m Source # | |
| (Ord a, Bounded a) => Monoid (Max a) # | Since: base-4.9.0.0 |
| (Ord a, Bounded a) => Monoid (Min a) # | Since: base-4.9.0.0 |
| Monoid b => Monoid (a -> b) # | Since: base-2.1 |
| (Monoid a, Monoid b) => Monoid (a, b) # | Since: base-2.1 |
| Monoid a => Monoid (ST s a) # | Since: base-4.11.0.0 |
| Monoid (Proxy s) # | Since: base-4.7.0.0 |
| (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) # | Since: base-2.1 |
| Alternative f => Monoid (Alt f a) # | Since: base-4.8.0.0 |
| Monoid a => Monoid (Const a b) # | |
| (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) # | Since: base-2.1 |
| (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) # | Since: base-2.1 |
Monads and functors
class Functor f where Source #
The Functor class is used for types that can be mapped over.
Instances of Functor should satisfy the following laws:
fmap id == id fmap (f . g) == fmap f . fmap g
The instances of Functor for lists, Maybe and IO
satisfy these laws.
Minimal complete definition
Instances
| Functor [] # | Since: base-2.1 |
| Functor Maybe # | Since: base-2.1 |
| Functor IO # | Since: base-2.1 |
| Functor Par1 # | |
| Functor NonEmpty # | Since: base-4.9.0.0 |
| Functor ReadP # | Since: base-2.1 |
| Functor ReadPrec # | Since: base-2.1 |
| Functor Down # | Since: base-4.11.0.0 |
| Functor Product # | Since: base-4.8.0.0 |
| Functor Sum # | Since: base-4.8.0.0 |
| Functor Dual # | Since: base-4.8.0.0 |
| Functor Last # | |
| Functor First # | |
| Functor STM # | Since: base-4.3.0.0 |
| Functor Handler # | Since: base-4.6.0.0 |
| Functor Identity # | Since: base-4.8.0.0 |
| Functor ZipList # | |
| Functor ArgDescr # | Since: base-4.6.0.0 |
| Functor OptDescr # | Since: base-4.6.0.0 |
| Functor ArgOrder # | Since: base-4.6.0.0 |
| Functor Option # | Since: base-4.9.0.0 |
| Functor Last # | Since: base-4.9.0.0 |
| Functor First # | Since: base-4.9.0.0 |
| Functor Max # | Since: base-4.9.0.0 |
| Functor Min # | Since: base-4.9.0.0 |
| Functor Complex # | |
| Functor (Either a) # | Since: base-3.0 |
| Functor (V1 :: * -> *) # | Since: base-4.9.0.0 |
| Functor (U1 :: * -> *) # | Since: base-4.9.0.0 |
| Functor ((,) a) # | Since: base-2.1 |
| Functor (ST s) # | Since: base-2.1 |
| Functor (Proxy :: * -> *) # | Since: base-4.7.0.0 |
| Arrow a => Functor (ArrowMonad a) # | Since: base-4.6.0.0 |
Defined in Control.Arrow Methods fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source # (<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 Source # | |
| Monad m => Functor (WrappedMonad m) # | Since: base-2.1 |
Defined in Control.Applicative Methods fmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b Source # (<$) :: a -> WrappedMonad m b -> WrappedMonad m a Source # | |
| Functor (ST s) # | Since: base-2.1 |
| Functor (Arg a) # | Since: base-4.9.0.0 |
| Functor f => Functor (Rec1 f) # | |
| Functor (URec Char :: * -> *) # | |
| Functor (URec Double :: * -> *) # | |
| Functor (URec Float :: * -> *) # | |
| Functor (URec Int :: * -> *) # | |
| Functor (URec Word :: * -> *) # | |
| Functor (URec (Ptr ()) :: * -> *) # | |
| Functor f => Functor (Alt f) # | |
| Functor (Const m :: * -> *) # | Since: base-2.1 |
| Arrow a => Functor (WrappedArrow a b) # | Since: base-2.1 |
Defined in Control.Applicative Methods fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 Source # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 Source # | |
| Functor ((->) r :: * -> *) # | Since: base-2.1 |
| Functor (K1 i c :: * -> *) # | |
| (Functor f, Functor g) => Functor (f :+: g) # | |
| (Functor f, Functor g) => Functor (f :*: g) # | |
| (Functor f, Functor g) => Functor (Sum f g) # | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (Product f g) # | Since: base-4.9.0.0 |
| Functor f => Functor (M1 i c f) # | |
| (Functor f, Functor g) => Functor (f :.: g) # | |
| (Functor f, Functor g) => Functor (Compose f g) # | Since: base-4.9.0.0 |
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 Source #
An infix synonym for fmap.
The name of this operator is an allusion to $.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $ is function application, <$> is function
application lifted over a Functor.
Examples
Convert from a to a Maybe Int using Maybe Stringshow:
>>>show <$> NothingNothing>>>show <$> Just 3Just "3"
Convert from an to an Either Int IntEither IntString using show:
>>>show <$> Left 17Left 17>>>show <$> Right 17Right "17"
Double each element of a list:
>>>(*2) <$> [1,2,3][2,4,6]
Apply even to the second element of a pair:
>>>even <$> (2,2)(2,True)
class Functor f => Applicative f where Source #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*> or liftA2. If it defines both, then they must behave
the same as their default definitions:
(<*>) =liftA2id
liftA2f x y = f<$>x<*>y
Further, any definition must satisfy the following:
- identity
pureid<*>v = v- composition
pure(.)<*>u<*>v<*>w = u<*>(v<*>w)- homomorphism
puref<*>purex =pure(f x)- interchange
u
<*>purey =pure($y)<*>u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor instance for f will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2p (liftA2q u v) =liftA2f u .liftA2g v
If f is also a Monad, it should satisfy
(which implies that pure and <*> satisfy the applicative functor laws).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 Source #
Sequential application.
A few functors support an implementation of <*> that is more
efficient than the default one.
(*>) :: f a -> f b -> f b infixl 4 Source #
Sequence actions, discarding the value of the first argument.
(<*) :: f a -> f b -> f a infixl 4 Source #
Sequence actions, discarding the value of the second argument.
Instances
| Applicative [] # | Since: base-2.1 |
| Applicative Maybe # | Since: base-2.1 |
| Applicative IO # | Since: base-2.1 |
| Applicative Par1 # | Since: base-4.9.0.0 |
| Applicative NonEmpty # | Since: base-4.9.0.0 |
Defined in GHC.Base | |
| Applicative ReadP # | Since: base-4.6.0.0 |
| Applicative ReadPrec # | Since: base-4.6.0.0 |
Defined in Text.ParserCombinators.ReadPrec | |
| Applicative Down # | Since: base-4.11.0.0 |
| Applicative Product # | Since: base-4.8.0.0 |
Defined in Data.Semigroup.Internal | |
| Applicative Sum # | Since: base-4.8.0.0 |
| Applicative Dual # | Since: base-4.8.0.0 |
| Applicative Last # | |
| Applicative First # | |
| Applicative STM # | Since: base-4.8.0.0 |
| Applicative Identity # | Since: base-4.8.0.0 |
Defined in Data.Functor.Identity | |
| Applicative ZipList # | f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsN
= 'ZipList' (zipWithN f xs1 ... xsN)where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..]
= ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..])
= ZipList {getZipList = ["a5","b6b6","c7c7c7"]}Since: base-2.1 |
Defined in Control.Applicative | |
| Applicative Option # | Since: base-4.9.0.0 |
| Applicative Last # | Since: base-4.9.0.0 |
| Applicative First # | Since: base-4.9.0.0 |
| Applicative Max # | Since: base-4.9.0.0 |
| Applicative Min # | Since: base-4.9.0.0 |
| Applicative Complex # | Since: base-4.9.0.0 |
| Applicative (Either e) # | Since: base-3.0 |
Defined in Data.Either | |
| Applicative (U1 :: * -> *) # | Since: base-4.9.0.0 |
| Monoid a => Applicative ((,) a) # | For tuples, the ("hello ", (+15)) <*> ("world!", 2002)
("hello world!",2017)Since: base-2.1 |
| Applicative (ST s) # | Since: base-4.4.0.0 |
| Applicative (Proxy :: * -> *) # | Since: base-4.7.0.0 |
| Arrow a => Applicative (ArrowMonad a) # | Since: base-4.6.0.0 |
Defined in Control.Arrow Methods pure :: a0 -> ArrowMonad a a0 Source # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c Source # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 Source # | |
| Monad m => Applicative (WrappedMonad m) # | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a -> WrappedMonad m a Source # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b Source # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c Source # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b Source # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a Source # | |
| Applicative (ST s) # | Since: base-2.1 |
| Applicative f => Applicative (Rec1 f) # | Since: base-4.9.0.0 |
| Applicative f => Applicative (Alt f) # | |
| Monoid m => Applicative (Const m :: * -> *) # | Since: base-2.0.1 |
Defined in Data.Functor.Const | |
| Arrow a => Applicative (WrappedArrow a b) # | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a0 -> WrappedArrow a b a0 Source # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 Source # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c Source # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 Source # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 Source # | |
| Applicative ((->) a :: * -> *) # | Since: base-2.1 |
| (Applicative f, Applicative g) => Applicative (f :*: g) # | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| (Applicative f, Applicative g) => Applicative (Product f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Product Methods pure :: a -> Product f g a Source # (<*>) :: Product f g (a -> b) -> Product f g a -> Product f g b Source # liftA2 :: (a -> b -> c) -> Product f g a -> Product f g b -> Product f g c Source # (*>) :: Product f g a -> Product f g b -> Product f g b Source # (<*) :: Product f g a -> Product f g b -> Product f g a Source # | |
| Applicative f => Applicative (M1 i c f) # | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| (Applicative f, Applicative g) => Applicative (f :.: g) # | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
| (Applicative f, Applicative g) => Applicative (Compose f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose Methods pure :: a -> Compose f g a Source # (<*>) :: Compose f g (a -> b) -> Compose f g a -> Compose f g b Source # liftA2 :: (a -> b -> c) -> Compose f g a -> Compose f g b -> Compose f g c Source # (*>) :: Compose f g a -> Compose f g b -> Compose f g b Source # (<*) :: Compose f g a -> Compose f g b -> Compose f g a Source # | |
class Applicative m => Monad m where Source #
The Monad class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad should satisfy the following laws:
Furthermore, the Monad and Applicative operations should relate as follows:
The above laws imply:
and that pure and (<*>) satisfy the applicative functor laws.
The instances of Monad for lists, Maybe and IO
defined in the Prelude satisfy these laws.
Minimal complete definition
Methods
(>>=) :: forall a b. m a -> (a -> m b) -> m b infixl 1 Source #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
(>>) :: forall a b. m a -> m b -> m b infixl 1 Source #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
Inject a value into the monadic type.
fail :: String -> m a Source #
Fail with a message. This operation is not part of the
mathematical definition of a monad, but is invoked on pattern-match
failure in a do expression.
As part of the MonadFail proposal (MFP), this function is moved
to its own class MonadFail (see Control.Monad.Fail for more
details). The definition here will be removed in a future
release.
Instances
| Monad [] # | Since: base-2.1 |
| Monad Maybe # | Since: base-2.1 |
| Monad IO # | Since: base-2.1 |
| Monad Par1 # | Since: base-4.9.0.0 |
| Monad NonEmpty # | Since: base-4.9.0.0 |
| Monad ReadP # | Since: base-2.1 |
| Monad ReadPrec # | Since: base-2.1 |
| Monad Down # | Since: base-4.11.0.0 |
| Monad Product # | Since: base-4.8.0.0 |
| Monad Sum # | Since: base-4.8.0.0 |
| Monad Dual # | Since: base-4.8.0.0 |
| Monad Last # | |
| Monad First # | |
| Monad STM # | Since: base-4.3.0.0 |
| Monad Identity # | Since: base-4.8.0.0 |
| Monad Option # | Since: base-4.9.0.0 |
| Monad Last # | Since: base-4.9.0.0 |
| Monad First # | Since: base-4.9.0.0 |
| Monad Max # | Since: base-4.9.0.0 |
| Monad Min # | Since: base-4.9.0.0 |
| Monad Complex # | Since: base-4.9.0.0 |
| Monad (Either e) # | Since: base-4.4.0.0 |
| Monad (U1 :: * -> *) # | Since: base-4.9.0.0 |
| Monoid a => Monad ((,) a) # | Since: base-4.9.0.0 |
| Monad (ST s) # | Since: base-2.1 |
| Monad (Proxy :: * -> *) # | Since: base-4.7.0.0 |
| ArrowApply a => Monad (ArrowMonad a) # | Since: base-2.1 |
Defined in Control.Arrow Methods (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b Source # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source # return :: a0 -> ArrowMonad a a0 Source # fail :: String -> ArrowMonad a a0 Source # | |
| Monad m => Monad (WrappedMonad m) # | |
Defined in Control.Applicative Methods (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b Source # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b Source # return :: a -> WrappedMonad m a Source # fail :: String -> WrappedMonad m a Source # | |
| Monad (ST s) # | Since: base-2.1 |
| Monad f => Monad (Rec1 f) # | Since: base-4.9.0.0 |
| Monad f => Monad (Alt f) # | |
| Monad ((->) r :: * -> *) # | Since: base-2.1 |
| (Monad f, Monad g) => Monad (f :*: g) # | Since: base-4.9.0.0 |
| (Monad f, Monad g) => Monad (Product f g) # | Since: base-4.9.0.0 |
| Monad f => Monad (M1 i c f) # | Since: base-4.9.0.0 |
sequence_ :: (Foldable t, Monad m) => t (m a) -> m () Source #
Evaluate each monadic action in the structure from left to right,
and ignore the results. For a version that doesn't ignore the
results see sequence.
As of base 4.8.0.0, sequence_ is just sequenceA_, specialized
to Monad.
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 Source #
Same as >>=, but with the arguments interchanged.
Folds and traversals
class Foldable t where Source #
Data structures that can be folded.
For example, given a data type
data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
a suitable instance would be
instance Foldable Tree where foldMap f Empty = mempty foldMap f (Leaf x) = f x foldMap f (Node l k r) = foldMap f l `mappend` f k `mappend` foldMap f r
This is suitable even for abstract types, as the monoid is assumed
to satisfy the monoid laws. Alternatively, one could define foldr:
instance Foldable Tree where foldr f z Empty = z foldr f z (Leaf x) = f x z foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l
Foldable instances are expected to satisfy the following laws:
foldr f z t = appEndo (foldMap (Endo . f) t ) z
foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
fold = foldMap id
length = getSum . foldMap (Sum . const 1)
sum, product, maximum, and minimum should all be essentially
equivalent to foldMap forms, such as
sum = getSum . foldMap Sum
but may be less defined.
If the type is also a Functor instance, it should satisfy
foldMap f = fold . fmap f
which implies that
foldMap f . fmap g = foldMap (f . g)
Methods
foldMap :: Monoid m => (a -> m) -> t a -> m Source #
Map each element of the structure to a monoid, and combine the results.
foldr :: (a -> b -> b) -> b -> t a -> b Source #
Right-associative fold of a structure.
In the case of lists, foldr, when applied to a binary operator, a
starting value (typically the right-identity of the operator), and a
list, reduces the list using the binary operator, from right to left:
foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
Note that, since the head of the resulting expression is produced by
an application of the operator to the first element of the list,
foldr can produce a terminating expression from an infinite list.
For a general Foldable structure this should be semantically identical
to,
foldr f z =foldrf z .toList
foldl :: (b -> a -> b) -> b -> t a -> b Source #
Left-associative fold of a structure.
In the case of lists, foldl, when applied to a binary
operator, a starting value (typically the left-identity of the operator),
and a list, reduces the list using the binary operator, from left to
right:
foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
Note that to produce the outermost application of the operator the
entire input list must be traversed. This means that foldl' will
diverge if given an infinite list.
Also note that if you want an efficient left-fold, you probably want to
use foldl' instead of foldl. The reason for this is that latter does
not force the "inner" results (e.g. z in the above example)
before applying them to the operator (e.g. to f x1(). This results
in a thunk chain f x2)O(n) elements long, which then must be evaluated from
the outside-in.
For a general Foldable structure this should be semantically identical
to,
foldl f z =foldlf z .toList
foldr1 :: (a -> a -> a) -> t a -> a Source #
A variant of foldr that has no base case,
and thus may only be applied to non-empty structures.
foldr1f =foldr1f .toList
foldl1 :: (a -> a -> a) -> t a -> a Source #
A variant of foldl that has no base case,
and thus may only be applied to non-empty structures.
foldl1f =foldl1f .toList
elem :: Eq a => a -> t a -> Bool infix 4 Source #
Does the element occur in the structure?
maximum :: forall a. Ord a => t a -> a Source #
The largest element of a non-empty structure.
minimum :: forall a. Ord a => t a -> a Source #
The least element of a non-empty structure.
sum :: Num a => t a -> a Source #
The sum function computes the sum of the numbers of a structure.
product :: Num a => t a -> a Source #
The product function computes the product of the numbers of a
structure.
Instances
| Foldable [] # | Since: base-2.1 |
Defined in Data.Foldable Methods fold :: Monoid m => [m] -> m Source # foldMap :: Monoid m => (a -> m) -> [a] -> m Source # foldr :: (a -> b -> b) -> b -> [a] -> b Source # foldr' :: (a -> b -> b) -> b -> [a] -> b Source # foldl :: (b -> a -> b) -> b -> [a] -> b Source # foldl' :: (b -> a -> b) -> b -> [a] -> b Source # foldr1 :: (a -> a -> a) -> [a] -> a Source # foldl1 :: (a -> a -> a) -> [a] -> a Source # elem :: Eq a => a -> [a] -> Bool Source # maximum :: Ord a => [a] -> a Source # minimum :: Ord a => [a] -> a Source # | |
| Foldable Maybe # | Since: base-2.1 |
Defined in Data.Foldable Methods fold :: Monoid m => Maybe m -> m Source # foldMap :: Monoid m => (a -> m) -> Maybe a -> m Source # foldr :: (a -> b -> b) -> b -> Maybe a -> b Source # foldr' :: (a -> b -> b) -> b -> Maybe a -> b Source # foldl :: (b -> a -> b) -> b -> Maybe a -> b Source # foldl' :: (b -> a -> b) -> b -> Maybe a -> b Source # foldr1 :: (a -> a -> a) -> Maybe a -> a Source # foldl1 :: (a -> a -> a) -> Maybe a -> a Source # toList :: Maybe a -> [a] Source # null :: Maybe a -> Bool Source # length :: Maybe a -> Int Source # elem :: Eq a => a -> Maybe a -> Bool Source # maximum :: Ord a => Maybe a -> a Source # minimum :: Ord a => Maybe a -> a Source # | |
| Foldable Par1 # | |
Defined in Data.Foldable Methods fold :: Monoid m => Par1 m -> m Source # foldMap :: Monoid m => (a -> m) -> Par1 a -> m Source # foldr :: (a -> b -> b) -> b -> Par1 a -> b Source # foldr' :: (a -> b -> b) -> b -> Par1 a -> b Source # foldl :: (b -> a -> b) -> b -> Par1 a -> b Source # foldl' :: (b -> a -> b) -> b -> Par1 a -> b Source # foldr1 :: (a -> a -> a) -> Par1 a -> a Source # foldl1 :: (a -> a -> a) -> Par1 a -> a Source # toList :: Par1 a -> [a] Source # null :: Par1 a -> Bool Source # length :: Par1 a -> Int Source # elem :: Eq a => a -> Par1 a -> Bool Source # maximum :: Ord a => Par1 a -> a Source # minimum :: Ord a => Par1 a -> a Source # | |
| Foldable NonEmpty # | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => NonEmpty m -> m Source # foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m Source # foldr :: (a -> b -> b) -> b -> NonEmpty a -> b Source # foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b Source # foldl :: (b -> a -> b) -> b -> NonEmpty a -> b Source # foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b Source # foldr1 :: (a -> a -> a) -> NonEmpty a -> a Source # foldl1 :: (a -> a -> a) -> NonEmpty a -> a Source # toList :: NonEmpty a -> [a] Source # null :: NonEmpty a -> Bool Source # length :: NonEmpty a -> Int Source # elem :: Eq a => a -> NonEmpty a -> Bool Source # maximum :: Ord a => NonEmpty a -> a Source # minimum :: Ord a => NonEmpty a -> a Source # | |
| Foldable Product # | Since: base-4.8.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Product m -> m Source # foldMap :: Monoid m => (a -> m) -> Product a -> m Source # foldr :: (a -> b -> b) -> b -> Product a -> b Source # foldr' :: (a -> b -> b) -> b -> Product a -> b Source # foldl :: (b -> a -> b) -> b -> Product a -> b Source # foldl' :: (b -> a -> b) -> b -> Product a -> b Source # foldr1 :: (a -> a -> a) -> Product a -> a Source # foldl1 :: (a -> a -> a) -> Product a -> a Source # toList :: Product a -> [a] Source # null :: Product a -> Bool Source # length :: Product a -> Int Source # elem :: Eq a => a -> Product a -> Bool Source # maximum :: Ord a => Product a -> a Source # minimum :: Ord a => Product a -> a Source # | |
| Foldable Sum # | Since: base-4.8.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Sum m -> m Source # foldMap :: Monoid m => (a -> m) -> Sum a -> m Source # foldr :: (a -> b -> b) -> b -> Sum a -> b Source # foldr' :: (a -> b -> b) -> b -> Sum a -> b Source # foldl :: (b -> a -> b) -> b -> Sum a -> b Source # foldl' :: (b -> a -> b) -> b -> Sum a -> b Source # foldr1 :: (a -> a -> a) -> Sum a -> a Source # foldl1 :: (a -> a -> a) -> Sum a -> a Source # toList :: Sum a -> [a] Source # null :: Sum a -> Bool Source # length :: Sum a -> Int Source # elem :: Eq a => a -> Sum a -> Bool Source # maximum :: Ord a => Sum a -> a Source # minimum :: Ord a => Sum a -> a Source # | |
| Foldable Dual # | Since: base-4.8.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Dual m -> m Source # foldMap :: Monoid m => (a -> m) -> Dual a -> m Source # foldr :: (a -> b -> b) -> b -> Dual a -> b Source # foldr' :: (a -> b -> b) -> b -> Dual a -> b Source # foldl :: (b -> a -> b) -> b -> Dual a -> b Source # foldl' :: (b -> a -> b) -> b -> Dual a -> b Source # foldr1 :: (a -> a -> a) -> Dual a -> a Source # foldl1 :: (a -> a -> a) -> Dual a -> a Source # toList :: Dual a -> [a] Source # null :: Dual a -> Bool Source # length :: Dual a -> Int Source # elem :: Eq a => a -> Dual a -> Bool Source # maximum :: Ord a => Dual a -> a Source # minimum :: Ord a => Dual a -> a Source # | |
| Foldable Last # | Since: base-4.8.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Last m -> m Source # foldMap :: Monoid m => (a -> m) -> Last a -> m Source # foldr :: (a -> b -> b) -> b -> Last a -> b Source # foldr' :: (a -> b -> b) -> b -> Last a -> b Source # foldl :: (b -> a -> b) -> b -> Last a -> b Source # foldl' :: (b -> a -> b) -> b -> Last a -> b Source # foldr1 :: (a -> a -> a) -> Last a -> a Source # foldl1 :: (a -> a -> a) -> Last a -> a Source # toList :: Last a -> [a] Source # null :: Last a -> Bool Source # length :: Last a -> Int Source # elem :: Eq a => a -> Last a -> Bool Source # maximum :: Ord a => Last a -> a Source # minimum :: Ord a => Last a -> a Source # | |
| Foldable First # | Since: base-4.8.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => First m -> m Source # foldMap :: Monoid m => (a -> m) -> First a -> m Source # foldr :: (a -> b -> b) -> b -> First a -> b Source # foldr' :: (a -> b -> b) -> b -> First a -> b Source # foldl :: (b -> a -> b) -> b -> First a -> b Source # foldl' :: (b -> a -> b) -> b -> First a -> b Source # foldr1 :: (a -> a -> a) -> First a -> a Source # foldl1 :: (a -> a -> a) -> First a -> a Source # toList :: First a -> [a] Source # null :: First a -> Bool Source # length :: First a -> Int Source # elem :: Eq a => a -> First a -> Bool Source # maximum :: Ord a => First a -> a Source # minimum :: Ord a => First a -> a Source # | |
| Foldable Identity # | Since: base-4.8.0.0 |
Defined in Data.Functor.Identity Methods fold :: Monoid m => Identity m -> m Source # foldMap :: Monoid m => (a -> m) -> Identity a -> m Source # foldr :: (a -> b -> b) -> b -> Identity a -> b Source # foldr' :: (a -> b -> b) -> b -> Identity a -> b Source # foldl :: (b -> a -> b) -> b -> Identity a -> b Source # foldl' :: (b -> a -> b) -> b -> Identity a -> b Source # foldr1 :: (a -> a -> a) -> Identity a -> a Source # foldl1 :: (a -> a -> a) -> Identity a -> a Source # toList :: Identity a -> [a] Source # null :: Identity a -> Bool Source # length :: Identity a -> Int Source # elem :: Eq a => a -> Identity a -> Bool Source # maximum :: Ord a => Identity a -> a Source # minimum :: Ord a => Identity a -> a Source # | |
| Foldable ZipList # | |
Defined in Control.Applicative Methods fold :: Monoid m => ZipList m -> m Source # foldMap :: Monoid m => (a -> m) -> ZipList a -> m Source # foldr :: (a -> b -> b) -> b -> ZipList a -> b Source # foldr' :: (a -> b -> b) -> b -> ZipList a -> b Source # foldl :: (b -> a -> b) -> b -> ZipList a -> b Source # foldl' :: (b -> a -> b) -> b -> ZipList a -> b Source # foldr1 :: (a -> a -> a) -> ZipList a -> a Source # foldl1 :: (a -> a -> a) -> ZipList a -> a Source # toList :: ZipList a -> [a] Source # null :: ZipList a -> Bool Source # length :: ZipList a -> Int Source # elem :: Eq a => a -> ZipList a -> Bool Source # maximum :: Ord a => ZipList a -> a Source # minimum :: Ord a => ZipList a -> a Source # | |
| Foldable Option # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods fold :: Monoid m => Option m -> m Source # foldMap :: Monoid m => (a -> m) -> Option a -> m Source # foldr :: (a -> b -> b) -> b -> Option a -> b Source # foldr' :: (a -> b -> b) -> b -> Option a -> b Source # foldl :: (b -> a -> b) -> b -> Option a -> b Source # foldl' :: (b -> a -> b) -> b -> Option a -> b Source # foldr1 :: (a -> a -> a) -> Option a -> a Source # foldl1 :: (a -> a -> a) -> Option a -> a Source # toList :: Option a -> [a] Source # null :: Option a -> Bool Source # length :: Option a -> Int Source # elem :: Eq a => a -> Option a -> Bool Source # maximum :: Ord a => Option a -> a Source # minimum :: Ord a => Option a -> a Source # | |
| Foldable Last # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods fold :: Monoid m => Last m -> m Source # foldMap :: Monoid m => (a -> m) -> Last a -> m Source # foldr :: (a -> b -> b) -> b -> Last a -> b Source # foldr' :: (a -> b -> b) -> b -> Last a -> b Source # foldl :: (b -> a -> b) -> b -> Last a -> b Source # foldl' :: (b -> a -> b) -> b -> Last a -> b Source # foldr1 :: (a -> a -> a) -> Last a -> a Source # foldl1 :: (a -> a -> a) -> Last a -> a Source # toList :: Last a -> [a] Source # null :: Last a -> Bool Source # length :: Last a -> Int Source # elem :: Eq a => a -> Last a -> Bool Source # maximum :: Ord a => Last a -> a Source # minimum :: Ord a => Last a -> a Source # | |
| Foldable First # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods fold :: Monoid m => First m -> m Source # foldMap :: Monoid m => (a -> m) -> First a -> m Source # foldr :: (a -> b -> b) -> b -> First a -> b Source # foldr' :: (a -> b -> b) -> b -> First a -> b Source # foldl :: (b -> a -> b) -> b -> First a -> b Source # foldl' :: (b -> a -> b) -> b -> First a -> b Source # foldr1 :: (a -> a -> a) -> First a -> a Source # foldl1 :: (a -> a -> a) -> First a -> a Source # toList :: First a -> [a] Source # null :: First a -> Bool Source # length :: First a -> Int Source # elem :: Eq a => a -> First a -> Bool Source # maximum :: Ord a => First a -> a Source # minimum :: Ord a => First a -> a Source # | |
| Foldable Max # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods fold :: Monoid m => Max m -> m Source # foldMap :: Monoid m => (a -> m) -> Max a -> m Source # foldr :: (a -> b -> b) -> b -> Max a -> b Source # foldr' :: (a -> b -> b) -> b -> Max a -> b Source # foldl :: (b -> a -> b) -> b -> Max a -> b Source # foldl' :: (b -> a -> b) -> b -> Max a -> b Source # foldr1 :: (a -> a -> a) -> Max a -> a Source # foldl1 :: (a -> a -> a) -> Max a -> a Source # toList :: Max a -> [a] Source # null :: Max a -> Bool Source # length :: Max a -> Int Source # elem :: Eq a => a -> Max a -> Bool Source # maximum :: Ord a => Max a -> a Source # minimum :: Ord a => Max a -> a Source # | |
| Foldable Min # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods fold :: Monoid m => Min m -> m Source # foldMap :: Monoid m => (a -> m) -> Min a -> m Source # foldr :: (a -> b -> b) -> b -> Min a -> b Source # foldr' :: (a -> b -> b) -> b -> Min a -> b Source # foldl :: (b -> a -> b) -> b -> Min a -> b Source # foldl' :: (b -> a -> b) -> b -> Min a -> b Source # foldr1 :: (a -> a -> a) -> Min a -> a Source # foldl1 :: (a -> a -> a) -> Min a -> a Source # toList :: Min a -> [a] Source # null :: Min a -> Bool Source # length :: Min a -> Int Source # elem :: Eq a => a -> Min a -> Bool Source # maximum :: Ord a => Min a -> a Source # minimum :: Ord a => Min a -> a Source # | |
| Foldable Complex # | |
Defined in Data.Complex Methods fold :: Monoid m => Complex m -> m Source # foldMap :: Monoid m => (a -> m) -> Complex a -> m Source # foldr :: (a -> b -> b) -> b -> Complex a -> b Source # foldr' :: (a -> b -> b) -> b -> Complex a -> b Source # foldl :: (b -> a -> b) -> b -> Complex a -> b Source # foldl' :: (b -> a -> b) -> b -> Complex a -> b Source # foldr1 :: (a -> a -> a) -> Complex a -> a Source # foldl1 :: (a -> a -> a) -> Complex a -> a Source # toList :: Complex a -> [a] Source # null :: Complex a -> Bool Source # length :: Complex a -> Int Source # elem :: Eq a => a -> Complex a -> Bool Source # maximum :: Ord a => Complex a -> a Source # minimum :: Ord a => Complex a -> a Source # | |
| Foldable (Either a) # | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Either a m -> m Source # foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m Source # foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b Source # foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b Source # foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b Source # foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b Source # foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source # foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 Source # toList :: Either a a0 -> [a0] Source # null :: Either a a0 -> Bool Source # length :: Either a a0 -> Int Source # elem :: Eq a0 => a0 -> Either a a0 -> Bool Source # maximum :: Ord a0 => Either a a0 -> a0 Source # minimum :: Ord a0 => Either a a0 -> a0 Source # | |
| Foldable (V1 :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => V1 m -> m Source # foldMap :: Monoid m => (a -> m) -> V1 a -> m Source # foldr :: (a -> b -> b) -> b -> V1 a -> b Source # foldr' :: (a -> b -> b) -> b -> V1 a -> b Source # foldl :: (b -> a -> b) -> b -> V1 a -> b Source # foldl' :: (b -> a -> b) -> b -> V1 a -> b Source # foldr1 :: (a -> a -> a) -> V1 a -> a Source # foldl1 :: (a -> a -> a) -> V1 a -> a Source # toList :: V1 a -> [a] Source # length :: V1 a -> Int Source # elem :: Eq a => a -> V1 a -> Bool Source # maximum :: Ord a => V1 a -> a Source # minimum :: Ord a => V1 a -> a Source # | |
| Foldable (U1 :: * -> *) # | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => U1 m -> m Source # foldMap :: Monoid m => (a -> m) -> U1 a -> m Source # foldr :: (a -> b -> b) -> b -> U1 a -> b Source # foldr' :: (a -> b -> b) -> b -> U1 a -> b Source # foldl :: (b -> a -> b) -> b -> U1 a -> b Source # foldl' :: (b -> a -> b) -> b -> U1 a -> b Source # foldr1 :: (a -> a -> a) -> U1 a -> a Source # foldl1 :: (a -> a -> a) -> U1 a -> a Source # toList :: U1 a -> [a] Source # length :: U1 a -> Int Source # elem :: Eq a => a -> U1 a -> Bool Source # maximum :: Ord a => U1 a -> a Source # minimum :: Ord a => U1 a -> a Source # | |
| Foldable ((,) a) # | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => (a, m) -> m Source # foldMap :: Monoid m => (a0 -> m) -> (a, a0) -> m Source # foldr :: (a0 -> b -> b) -> b -> (a, a0) -> b Source # foldr' :: (a0 -> b -> b) -> b -> (a, a0) -> b Source # foldl :: (b -> a0 -> b) -> b -> (a, a0) -> b Source # foldl' :: (b -> a0 -> b) -> b -> (a, a0) -> b Source # foldr1 :: (a0 -> a0 -> a0) -> (a, a0) -> a0 Source # foldl1 :: (a0 -> a0 -> a0) -> (a, a0) -> a0 Source # toList :: (a, a0) -> [a0] Source # null :: (a, a0) -> Bool Source # length :: (a, a0) -> Int Source # elem :: Eq a0 => a0 -> (a, a0) -> Bool Source # maximum :: Ord a0 => (a, a0) -> a0 Source # minimum :: Ord a0 => (a, a0) -> a0 Source # | |
| Foldable (Proxy :: * -> *) # | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Proxy m -> m Source # foldMap :: Monoid m => (a -> m) -> Proxy a -> m Source # foldr :: (a -> b -> b) -> b -> Proxy a -> b Source # foldr' :: (a -> b -> b) -> b -> Proxy a -> b Source # foldl :: (b -> a -> b) -> b -> Proxy a -> b Source # foldl' :: (b -> a -> b) -> b -> Proxy a -> b Source # foldr1 :: (a -> a -> a) -> Proxy a -> a Source # foldl1 :: (a -> a -> a) -> Proxy a -> a Source # toList :: Proxy a -> [a] Source # null :: Proxy a -> Bool Source # length :: Proxy a -> Int Source # elem :: Eq a => a -> Proxy a -> Bool Source # maximum :: Ord a => Proxy a -> a Source # minimum :: Ord a => Proxy a -> a Source # | |
| Foldable (Arg a) # | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods fold :: Monoid m => Arg a m -> m Source # foldMap :: Monoid m => (a0 -> m) -> Arg a a0 -> m Source # foldr :: (a0 -> b -> b) -> b -> Arg a a0 -> b Source # foldr' :: (a0 -> b -> b) -> b -> Arg a a0 -> b Source # foldl :: (b -> a0 -> b) -> b -> Arg a a0 -> b Source # foldl' :: (b -> a0 -> b) -> b -> Arg a a0 -> b Source # foldr1 :: (a0 -> a0 -> a0) -> Arg a a0 -> a0 Source # foldl1 :: (a0 -> a0 -> a0) -> Arg a a0 -> a0 Source # toList :: Arg a a0 -> [a0] Source # null :: Arg a a0 -> Bool Source # length :: Arg a a0 -> Int Source # elem :: Eq a0 => a0 -> Arg a a0 -> Bool Source # maximum :: Ord a0 => Arg a a0 -> a0 Source # minimum :: Ord a0 => Arg a a0 -> a0 Source # | |
| Foldable f => Foldable (Rec1 f) # | |
Defined in Data.Foldable Methods fold :: Monoid m => Rec1 f m -> m Source # foldMap :: Monoid m => (a -> m) -> Rec1 f a -> m Source # foldr :: (a -> b -> b) -> b -> Rec1 f a -> b Source # foldr' :: (a -> b -> b) -> b -> Rec1 f a -> b Source # foldl :: (b -> a -> b) -> b -> Rec1 f a -> b Source # foldl' :: (b -> a -> b) -> b -> Rec1 f a -> b Source # foldr1 :: (a -> a -> a) -> Rec1 f a -> a Source # foldl1 :: (a -> a -> a) -> Rec1 f a -> a Source # toList :: Rec1 f a -> [a] Source # null :: Rec1 f a -> Bool Source # length :: Rec1 f a -> Int Source # elem :: Eq a => a -> Rec1 f a -> Bool Source # maximum :: Ord a => Rec1 f a -> a Source # minimum :: Ord a => Rec1 f a -> a Source # | |
| Foldable (URec Char :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Char m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Char a -> m Source # foldr :: (a -> b -> b) -> b -> URec Char a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Char a -> b Source # foldl :: (b -> a -> b) -> b -> URec Char a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Char a -> b Source # foldr1 :: (a -> a -> a) -> URec Char a -> a Source # foldl1 :: (a -> a -> a) -> URec Char a -> a Source # toList :: URec Char a -> [a] Source # null :: URec Char a -> Bool Source # length :: URec Char a -> Int Source # elem :: Eq a => a -> URec Char a -> Bool Source # maximum :: Ord a => URec Char a -> a Source # minimum :: Ord a => URec Char a -> a Source # | |
| Foldable (URec Double :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Double m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Double a -> m Source # foldr :: (a -> b -> b) -> b -> URec Double a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Double a -> b Source # foldl :: (b -> a -> b) -> b -> URec Double a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Double a -> b Source # foldr1 :: (a -> a -> a) -> URec Double a -> a Source # foldl1 :: (a -> a -> a) -> URec Double a -> a Source # toList :: URec Double a -> [a] Source # null :: URec Double a -> Bool Source # length :: URec Double a -> Int Source # elem :: Eq a => a -> URec Double a -> Bool Source # maximum :: Ord a => URec Double a -> a Source # minimum :: Ord a => URec Double a -> a Source # | |
| Foldable (URec Float :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Float m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Float a -> m Source # foldr :: (a -> b -> b) -> b -> URec Float a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Float a -> b Source # foldl :: (b -> a -> b) -> b -> URec Float a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Float a -> b Source # foldr1 :: (a -> a -> a) -> URec Float a -> a Source # foldl1 :: (a -> a -> a) -> URec Float a -> a Source # toList :: URec Float a -> [a] Source # null :: URec Float a -> Bool Source # length :: URec Float a -> Int Source # elem :: Eq a => a -> URec Float a -> Bool Source # maximum :: Ord a => URec Float a -> a Source # minimum :: Ord a => URec Float a -> a Source # | |
| Foldable (URec Int :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Int m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Int a -> m Source # foldr :: (a -> b -> b) -> b -> URec Int a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Int a -> b Source # foldl :: (b -> a -> b) -> b -> URec Int a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Int a -> b Source # foldr1 :: (a -> a -> a) -> URec Int a -> a Source # foldl1 :: (a -> a -> a) -> URec Int a -> a Source # toList :: URec Int a -> [a] Source # null :: URec Int a -> Bool Source # length :: URec Int a -> Int Source # elem :: Eq a => a -> URec Int a -> Bool Source # maximum :: Ord a => URec Int a -> a Source # minimum :: Ord a => URec Int a -> a Source # | |
| Foldable (URec Word :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec Word m -> m Source # foldMap :: Monoid m => (a -> m) -> URec Word a -> m Source # foldr :: (a -> b -> b) -> b -> URec Word a -> b Source # foldr' :: (a -> b -> b) -> b -> URec Word a -> b Source # foldl :: (b -> a -> b) -> b -> URec Word a -> b Source # foldl' :: (b -> a -> b) -> b -> URec Word a -> b Source # foldr1 :: (a -> a -> a) -> URec Word a -> a Source # foldl1 :: (a -> a -> a) -> URec Word a -> a Source # toList :: URec Word a -> [a] Source # null :: URec Word a -> Bool Source # length :: URec Word a -> Int Source # elem :: Eq a => a -> URec Word a -> Bool Source # maximum :: Ord a => URec Word a -> a Source # minimum :: Ord a => URec Word a -> a Source # | |
| Foldable (URec (Ptr ()) :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => URec (Ptr ()) m -> m Source # foldMap :: Monoid m => (a -> m) -> URec (Ptr ()) a -> m Source # foldr :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b Source # foldr' :: (a -> b -> b) -> b -> URec (Ptr ()) a -> b Source # foldl :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b Source # foldl' :: (b -> a -> b) -> b -> URec (Ptr ()) a -> b Source # foldr1 :: (a -> a -> a) -> URec (Ptr ()) a -> a Source # foldl1 :: (a -> a -> a) -> URec (Ptr ()) a -> a Source # toList :: URec (Ptr ()) a -> [a] Source # null :: URec (Ptr ()) a -> Bool Source # length :: URec (Ptr ()) a -> Int Source # elem :: Eq a => a -> URec (Ptr ()) a -> Bool Source # maximum :: Ord a => URec (Ptr ()) a -> a Source # minimum :: Ord a => URec (Ptr ()) a -> a Source # | |
| Foldable (Const m :: * -> *) # | Since: base-4.7.0.0 |
Defined in Data.Functor.Const Methods fold :: Monoid m0 => Const m m0 -> m0 Source # foldMap :: Monoid m0 => (a -> m0) -> Const m a -> m0 Source # foldr :: (a -> b -> b) -> b -> Const m a -> b Source # foldr' :: (a -> b -> b) -> b -> Const m a -> b Source # foldl :: (b -> a -> b) -> b -> Const m a -> b Source # foldl' :: (b -> a -> b) -> b -> Const m a -> b Source # foldr1 :: (a -> a -> a) -> Const m a -> a Source # foldl1 :: (a -> a -> a) -> Const m a -> a Source # toList :: Const m a -> [a] Source # null :: Const m a -> Bool Source # length :: Const m a -> Int Source # elem :: Eq a => a -> Const m a -> Bool Source # maximum :: Ord a => Const m a -> a Source # minimum :: Ord a => Const m a -> a Source # | |
| Foldable (K1 i c :: * -> *) # | |
Defined in Data.Foldable Methods fold :: Monoid m => K1 i c m -> m Source # foldMap :: Monoid m => (a -> m) -> K1 i c a -> m Source # foldr :: (a -> b -> b) -> b -> K1 i c a -> b Source # foldr' :: (a -> b -> b) -> b -> K1 i c a -> b Source # foldl :: (b -> a -> b) -> b -> K1 i c a -> b Source # foldl' :: (b -> a -> b) -> b -> K1 i c a -> b Source # foldr1 :: (a -> a -> a) -> K1 i c a -> a Source # foldl1 :: (a -> a -> a) -> K1 i c a -> a Source # toList :: K1 i c a -> [a] Source # null :: K1 i c a -> Bool Source # length :: K1 i c a -> Int Source # elem :: Eq a => a -> K1 i c a -> Bool Source # maximum :: Ord a => K1 i c a -> a Source # minimum :: Ord a => K1 i c a -> a Source # | |
| (Foldable f, Foldable g) => Foldable (f :+: g) # | |
Defined in Data.Foldable Methods fold :: Monoid m => (f :+: g) m -> m Source # foldMap :: Monoid m => (a -> m) -> (f :+: g) a -> m Source # foldr :: (a -> b -> b) -> b -> (f :+: g) a -> b Source # foldr' :: (a -> b -> b) -> b -> (f :+: g) a -> b Source # foldl :: (b -> a -> b) -> b -> (f :+: g) a -> b Source # foldl' :: (b -> a -> b) -> b -> (f :+: g) a -> b Source # foldr1 :: (a -> a -> a) -> (f :+: g) a -> a Source # foldl1 :: (a -> a -> a) -> (f :+: g) a -> a Source # toList :: (f :+: g) a -> [a] Source # null :: (f :+: g) a -> Bool Source # length :: (f :+: g) a -> Int Source # elem :: Eq a => a -> (f :+: g) a -> Bool Source # maximum :: Ord a => (f :+: g) a -> a Source # minimum :: Ord a => (f :+: g) a -> a Source # | |
| (Foldable f, Foldable g) => Foldable (f :*: g) # | |
Defined in Data.Foldable Methods fold :: Monoid m => (f :*: g) m -> m Source # foldMap :: Monoid m => (a -> m) -> (f :*: g) a -> m Source # foldr :: (a -> b -> b) -> b -> (f :*: g) a -> b Source # foldr' :: (a -> b -> b) -> b -> (f :*: g) a -> b Source # foldl :: (b -> a -> b) -> b -> (f :*: g) a -> b Source # foldl' :: (b -> a -> b) -> b -> (f :*: g) a -> b Source # foldr1 :: (a -> a -> a) -> (f :*: g) a -> a Source # foldl1 :: (a -> a -> a) -> (f :*: g) a -> a Source # toList :: (f :*: g) a -> [a] Source # null :: (f :*: g) a -> Bool Source # length :: (f :*: g) a -> Int Source # elem :: Eq a => a -> (f :*: g) a -> Bool Source # maximum :: Ord a => (f :*: g) a -> a Source # minimum :: Ord a => (f :*: g) a -> a Source # | |
| (Foldable f, Foldable g) => Foldable (Sum f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Sum Methods fold :: Monoid m => Sum f g m -> m Source # foldMap :: Monoid m => (a -> m) -> Sum f g a -> m Source # foldr :: (a -> b -> b) -> b -> Sum f g a -> b Source # foldr' :: (a -> b -> b) -> b -> Sum f g a -> b Source # foldl :: (b -> a -> b) -> b -> Sum f g a -> b Source # foldl' :: (b -> a -> b) -> b -> Sum f g a -> b Source # foldr1 :: (a -> a -> a) -> Sum f g a -> a Source # foldl1 :: (a -> a -> a) -> Sum f g a -> a Source # toList :: Sum f g a -> [a] Source # null :: Sum f g a -> Bool Source # length :: Sum f g a -> Int Source # elem :: Eq a => a -> Sum f g a -> Bool Source # maximum :: Ord a => Sum f g a -> a Source # minimum :: Ord a => Sum f g a -> a Source # | |
| (Foldable f, Foldable g) => Foldable (Product f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Product Methods fold :: Monoid m => Product f g m -> m Source # foldMap :: Monoid m => (a -> m) -> Product f g a -> m Source # foldr :: (a -> b -> b) -> b -> Product f g a -> b Source # foldr' :: (a -> b -> b) -> b -> Product f g a -> b Source # foldl :: (b -> a -> b) -> b -> Product f g a -> b Source # foldl' :: (b -> a -> b) -> b -> Product f g a -> b Source # foldr1 :: (a -> a -> a) -> Product f g a -> a Source # foldl1 :: (a -> a -> a) -> Product f g a -> a Source # toList :: Product f g a -> [a] Source # null :: Product f g a -> Bool Source # length :: Product f g a -> Int Source # elem :: Eq a => a -> Product f g a -> Bool Source # maximum :: Ord a => Product f g a -> a Source # minimum :: Ord a => Product f g a -> a Source # | |
| Foldable f => Foldable (M1 i c f) # | |
Defined in Data.Foldable Methods fold :: Monoid m => M1 i c f m -> m Source # foldMap :: Monoid m => (a -> m) -> M1 i c f a -> m Source # foldr :: (a -> b -> b) -> b -> M1 i c f a -> b Source # foldr' :: (a -> b -> b) -> b -> M1 i c f a -> b Source # foldl :: (b -> a -> b) -> b -> M1 i c f a -> b Source # foldl' :: (b -> a -> b) -> b -> M1 i c f a -> b Source # foldr1 :: (a -> a -> a) -> M1 i c f a -> a Source # foldl1 :: (a -> a -> a) -> M1 i c f a -> a Source # toList :: M1 i c f a -> [a] Source # null :: M1 i c f a -> Bool Source # length :: M1 i c f a -> Int Source # elem :: Eq a => a -> M1 i c f a -> Bool Source # maximum :: Ord a => M1 i c f a -> a Source # minimum :: Ord a => M1 i c f a -> a Source # | |
| (Foldable f, Foldable g) => Foldable (f :.: g) # | |
Defined in Data.Foldable Methods fold :: Monoid m => (f :.: g) m -> m Source # foldMap :: Monoid m => (a -> m) -> (f :.: g) a -> m Source # foldr :: (a -> b -> b) -> b -> (f :.: g) a -> b Source # foldr' :: (a -> b -> b) -> b -> (f :.: g) a -> b Source # foldl :: (b -> a -> b) -> b -> (f :.: g) a -> b Source # foldl' :: (b -> a -> b) -> b -> (f :.: g) a -> b Source # foldr1 :: (a -> a -> a) -> (f :.: g) a -> a Source # foldl1 :: (a -> a -> a) -> (f :.: g) a -> a Source # toList :: (f :.: g) a -> [a] Source # null :: (f :.: g) a -> Bool Source # length :: (f :.: g) a -> Int Source # elem :: Eq a => a -> (f :.: g) a -> Bool Source # maximum :: Ord a => (f :.: g) a -> a Source # minimum :: Ord a => (f :.: g) a -> a Source # | |
| (Foldable f, Foldable g) => Foldable (Compose f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose Methods fold :: Monoid m => Compose f g m -> m Source # foldMap :: Monoid m => (a -> m) -> Compose f g a -> m Source # foldr :: (a -> b -> b) -> b -> Compose f g a -> b Source # foldr' :: (a -> b -> b) -> b -> Compose f g a -> b Source # foldl :: (b -> a -> b) -> b -> Compose f g a -> b Source # foldl' :: (b -> a -> b) -> b -> Compose f g a -> b Source # foldr1 :: (a -> a -> a) -> Compose f g a -> a Source # foldl1 :: (a -> a -> a) -> Compose f g a -> a Source # toList :: Compose f g a -> [a] Source # null :: Compose f g a -> Bool Source # length :: Compose f g a -> Int Source # elem :: Eq a => a -> Compose f g a -> Bool Source # maximum :: Ord a => Compose f g a -> a Source # minimum :: Ord a => Compose f g a -> a Source # | |
class (Functor t, Foldable t) => Traversable t where Source #
Functors representing data structures that can be traversed from left to right.
A definition of traverse must satisfy the following laws:
- naturality
t .for every applicative transformationtraversef =traverse(t . f)t- identity
traverseIdentity = Identity- composition
traverse(Compose .fmapg . f) = Compose .fmap(traverseg) .traversef
A definition of sequenceA must satisfy the following laws:
- naturality
t .for every applicative transformationsequenceA=sequenceA.fmaptt- identity
sequenceA.fmapIdentity = Identity- composition
sequenceA.fmapCompose = Compose .fmapsequenceA.sequenceA
where an applicative transformation is a function
t :: (Applicative f, Applicative g) => f a -> g a
preserving the Applicative operations, i.e.
and the identity functor Identity and composition of functors Compose
are defined as
newtype Identity a = Identity a
instance Functor Identity where
fmap f (Identity x) = Identity (f x)
instance Applicative Identity where
pure x = Identity x
Identity f <*> Identity x = Identity (f x)
newtype Compose f g a = Compose (f (g a))
instance (Functor f, Functor g) => Functor (Compose f g) where
fmap f (Compose x) = Compose (fmap (fmap f) x)
instance (Applicative f, Applicative g) => Applicative (Compose f g) where
pure x = Compose (pure (pure x))
Compose f <*> Compose x = Compose ((<*>) <$> f <*> x)(The naturality law is implied by parametricity.)
Instances are similar to Functor, e.g. given a data type
data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
a suitable instance would be
instance Traversable Tree where traverse f Empty = pure Empty traverse f (Leaf x) = Leaf <$> f x traverse f (Node l k r) = Node <$> traverse f l <*> f k <*> traverse f r
This is suitable even for abstract types, as the laws for <*>
imply a form of associativity.
The superclass instances should satisfy the following:
- In the
Functorinstance,fmapshould be equivalent to traversal with the identity applicative functor (fmapDefault). - In the
Foldableinstance,foldMapshould be equivalent to traversal with a constant applicative functor (foldMapDefault).
Methods
traverse :: Applicative f => (a -> f b) -> t a -> f (t b) Source #
Map each element of a structure to an action, evaluate these actions
from left to right, and collect the results. For a version that ignores
the results see traverse_.
sequenceA :: Applicative f => t (f a) -> f (t a) Source #
Evaluate each action in the structure from left to right, and
and collect the results. For a version that ignores the results
see sequenceA_.
mapM :: Monad m => (a -> m b) -> t a -> m (t b) Source #
Map each element of a structure to a monadic action, evaluate
these actions from left to right, and collect the results. For
a version that ignores the results see mapM_.
sequence :: Monad m => t (m a) -> m (t a) Source #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_.
Instances
| Traversable [] # | Since: base-2.1 |
| Traversable Maybe # | Since: base-2.1 |
| Traversable Par1 # | |
| Traversable NonEmpty # | Since: base-4.9.0.0 |
Defined in Data.Traversable | |
| Traversable Product # | Since: base-4.8.0.0 |
Defined in Data.Traversable | |
| Traversable Sum # | Since: base-4.8.0.0 |
| Traversable Dual # | Since: base-4.8.0.0 |
| Traversable Last # | Since: base-4.8.0.0 |
| Traversable First # | Since: base-4.8.0.0 |
| Traversable Identity # | |
Defined in Data.Traversable | |
| Traversable ZipList # | Since: base-4.9.0.0 |
Defined in Data.Traversable | |
| Traversable Option # | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| Traversable Last # | Since: base-4.9.0.0 |
| Traversable First # | Since: base-4.9.0.0 |
| Traversable Max # | Since: base-4.9.0.0 |
| Traversable Min # | Since: base-4.9.0.0 |
| Traversable Complex # | |
Defined in Data.Complex | |
| Traversable (Either a) # | Since: base-4.7.0.0 |
Defined in Data.Traversable Methods traverse :: Applicative f => (a0 -> f b) -> Either a a0 -> f (Either a b) Source # sequenceA :: Applicative f => Either a (f a0) -> f (Either a a0) Source # mapM :: Monad m => (a0 -> m b) -> Either a a0 -> m (Either a b) Source # sequence :: Monad m => Either a (m a0) -> m (Either a a0) Source # | |
| Traversable (V1 :: * -> *) # | |
| Traversable (U1 :: * -> *) # | Since: base-4.9.0.0 |
| Traversable ((,) a) # | Since: base-4.7.0.0 |
| Traversable (Proxy :: * -> *) # | Since: base-4.7.0.0 |
| Traversable (Arg a) # | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| Traversable f => Traversable (Rec1 f) # | |
Defined in Data.Traversable | |
| Traversable (URec Char :: * -> *) # | |
Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Char a -> f (URec Char b) Source # sequenceA :: Applicative f => URec Char (f a) -> f (URec Char a) Source # mapM :: Monad m => (a -> m b) -> URec Char a -> m (URec Char b) Source # sequence :: Monad m => URec Char (m a) -> m (URec Char a) Source # | |
| Traversable (URec Double :: * -> *) # | |
Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Double a -> f (URec Double b) Source # sequenceA :: Applicative f => URec Double (f a) -> f (URec Double a) Source # mapM :: Monad m => (a -> m b) -> URec Double a -> m (URec Double b) Source # sequence :: Monad m => URec Double (m a) -> m (URec Double a) Source # | |
| Traversable (URec Float :: * -> *) # | |
Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Float a -> f (URec Float b) Source # sequenceA :: Applicative f => URec Float (f a) -> f (URec Float a) Source # mapM :: Monad m => (a -> m b) -> URec Float a -> m (URec Float b) Source # sequence :: Monad m => URec Float (m a) -> m (URec Float a) Source # | |
| Traversable (URec Int :: * -> *) # | |
Defined in Data.Traversable | |
| Traversable (URec Word :: * -> *) # | |
Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec Word a -> f (URec Word b) Source # sequenceA :: Applicative f => URec Word (f a) -> f (URec Word a) Source # mapM :: Monad m => (a -> m b) -> URec Word a -> m (URec Word b) Source # sequence :: Monad m => URec Word (m a) -> m (URec Word a) Source # | |
| Traversable (URec (Ptr ()) :: * -> *) # | |
Defined in Data.Traversable Methods traverse :: Applicative f => (a -> f b) -> URec (Ptr ()) a -> f (URec (Ptr ()) b) Source # sequenceA :: Applicative f => URec (Ptr ()) (f a) -> f (URec (Ptr ()) a) Source # mapM :: Monad m => (a -> m b) -> URec (Ptr ()) a -> m (URec (Ptr ()) b) Source # sequence :: Monad m => URec (Ptr ()) (m a) -> m (URec (Ptr ()) a) Source # | |
| Traversable (Const m :: * -> *) # | Since: base-4.7.0.0 |
Defined in Data.Traversable | |
| Traversable (K1 i c :: * -> *) # | |
Defined in Data.Traversable | |
| (Traversable f, Traversable g) => Traversable (f :+: g) # | |
Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> (f :+: g) a -> f0 ((f :+: g) b) Source # sequenceA :: Applicative f0 => (f :+: g) (f0 a) -> f0 ((f :+: g) a) Source # mapM :: Monad m => (a -> m b) -> (f :+: g) a -> m ((f :+: g) b) Source # sequence :: Monad m => (f :+: g) (m a) -> m ((f :+: g) a) Source # | |
| (Traversable f, Traversable g) => Traversable (f :*: g) # | |
Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> (f :*: g) a -> f0 ((f :*: g) b) Source # sequenceA :: Applicative f0 => (f :*: g) (f0 a) -> f0 ((f :*: g) a) Source # mapM :: Monad m => (a -> m b) -> (f :*: g) a -> m ((f :*: g) b) Source # sequence :: Monad m => (f :*: g) (m a) -> m ((f :*: g) a) Source # | |
| (Traversable f, Traversable g) => Traversable (Sum f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Sum | |
| (Traversable f, Traversable g) => Traversable (Product f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Product Methods traverse :: Applicative f0 => (a -> f0 b) -> Product f g a -> f0 (Product f g b) Source # sequenceA :: Applicative f0 => Product f g (f0 a) -> f0 (Product f g a) Source # mapM :: Monad m => (a -> m b) -> Product f g a -> m (Product f g b) Source # sequence :: Monad m => Product f g (m a) -> m (Product f g a) Source # | |
| Traversable f => Traversable (M1 i c f) # | |
Defined in Data.Traversable | |
| (Traversable f, Traversable g) => Traversable (f :.: g) # | |
Defined in Data.Traversable Methods traverse :: Applicative f0 => (a -> f0 b) -> (f :.: g) a -> f0 ((f :.: g) b) Source # sequenceA :: Applicative f0 => (f :.: g) (f0 a) -> f0 ((f :.: g) a) Source # mapM :: Monad m => (a -> m b) -> (f :.: g) a -> m ((f :.: g) b) Source # sequence :: Monad m => (f :.: g) (m a) -> m ((f :.: g) a) Source # | |
| (Traversable f, Traversable g) => Traversable (Compose f g) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose Methods traverse :: Applicative f0 => (a -> f0 b) -> Compose f g a -> f0 (Compose f g b) Source # sequenceA :: Applicative f0 => Compose f g (f0 a) -> f0 (Compose f g a) Source # mapM :: Monad m => (a -> m b) -> Compose f g a -> m (Compose f g b) Source # sequence :: Monad m => Compose f g (m a) -> m (Compose f g a) Source # | |
Miscellaneous functions
const x is a unary function which evaluates to x for all inputs.
>>>const 42 "hello"42
>>>map (const 42) [0..3][42,42,42,42]
flip :: (a -> b -> c) -> b -> a -> c Source #
takes its (first) two arguments in the reverse order of flip ff.
>>>flip (++) "hello" "world""worldhello"
($) :: (a -> b) -> a -> b infixr 0 Source #
Application operator. This operator is redundant, since ordinary
application (f x) means the same as (f . However, $ x)$ has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
It is also useful in higher-order situations, such as ,
or map ($ 0) xs.zipWith ($) fs xs
until :: (a -> Bool) -> (a -> a) -> a -> a Source #
yields the result of applying until p ff until p holds.
error :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => [Char] -> a Source #
error stops execution and displays an error message.
errorWithoutStackTrace :: forall (r :: RuntimeRep). forall (a :: TYPE r). [Char] -> a Source #
A variant of error that does not produce a stack trace.
Since: base-4.9.0.0
undefined :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => a Source #
The value of seq a b is bottom if a is bottom, and
otherwise equal to b. In other words, it evaluates the first
argument a to weak head normal form (WHNF). seq is usually
introduced to improve performance by avoiding unneeded laziness.
A note on evaluation order: the expression seq a b does
not guarantee that a will be evaluated before b.
The only guarantee given by seq is that the both a
and b will be evaluated before seq returns a value.
In particular, this means that b may be evaluated before
a. If you need to guarantee a specific order of evaluation,
you must use the function pseq from the "parallel" package.
($!) :: (a -> b) -> a -> b infixr 0 Source #
Strict (call-by-value) application operator. It takes a function and an argument, evaluates the argument to weak head normal form (WHNF), then calls the function with that value.
List operations
map :: (a -> b) -> [a] -> [b] Source #
map f xs is the list obtained by applying f to each element
of xs, i.e.,
map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn] map f [x1, x2, ...] == [f x1, f x2, ...]
(++) :: [a] -> [a] -> [a] infixr 5 Source #
Append two lists, i.e.,
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn] [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
If the first list is not finite, the result is the first list.
filter :: (a -> Bool) -> [a] -> [a] Source #
filter, applied to a predicate and a list, returns the list of
those elements that satisfy the predicate; i.e.,
filter p xs = [ x | x <- xs, p x]
Return all the elements of a list except the last one. The list must be non-empty.
null :: Foldable t => t a -> Bool Source #
Test whether the structure is empty. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.
length :: Foldable t => t a -> Int Source #
Returns the size/length of a finite structure as an Int. The
default implementation is optimized for structures that are similar to
cons-lists, because there is no general way to do better.
(!!) :: [a] -> Int -> a infixl 9 Source #
List index (subscript) operator, starting from 0.
It is an instance of the more general genericIndex,
which takes an index of any integral type.
reverse :: [a] -> [a] Source #
reverse xs returns the elements of xs in reverse order.
xs must be finite.
Special folds
any :: Foldable t => (a -> Bool) -> t a -> Bool Source #
Determines whether any element of the structure satisfies the predicate.
all :: Foldable t => (a -> Bool) -> t a -> Bool Source #
Determines whether all elements of the structure satisfy the predicate.
concat :: Foldable t => t [a] -> [a] Source #
The concatenation of all the elements of a container of lists.
concatMap :: Foldable t => (a -> [b]) -> t a -> [b] Source #
Map a function over all the elements of a container and concatenate the resulting lists.
Building lists
Scans
Infinite lists
replicate :: Int -> a -> [a] Source #
replicate n x is a list of length n with x the value of
every element.
It is an instance of the more general genericReplicate,
in which n may be of any integral type.
cycle ties a finite list into a circular one, or equivalently,
the infinite repetition of the original list. It is the identity
on infinite lists.
Sublists
take :: Int -> [a] -> [a] Source #
take n, applied to a list xs, returns the prefix of xs
of length n, or xs itself if n > :length xs
take 5 "Hello World!" == "Hello" take 3 [1,2,3,4,5] == [1,2,3] take 3 [1,2] == [1,2] take 3 [] == [] take (-1) [1,2] == [] take 0 [1,2] == []
It is an instance of the more general genericTake,
in which n may be of any integral type.
drop :: Int -> [a] -> [a] Source #
drop n xs returns the suffix of xs
after the first n elements, or [] if n > :length xs
drop 6 "Hello World!" == "World!" drop 3 [1,2,3,4,5] == [4,5] drop 3 [1,2] == [] drop 3 [] == [] drop (-1) [1,2] == [1,2] drop 0 [1,2] == [1,2]
It is an instance of the more general genericDrop,
in which n may be of any integral type.
splitAt :: Int -> [a] -> ([a], [a]) Source #
splitAt n xs returns a tuple where first element is xs prefix of
length n and second element is the remainder of the list:
splitAt 6 "Hello World!" == ("Hello ","World!")
splitAt 3 [1,2,3,4,5] == ([1,2,3],[4,5])
splitAt 1 [1,2,3] == ([1],[2,3])
splitAt 3 [1,2,3] == ([1,2,3],[])
splitAt 4 [1,2,3] == ([1,2,3],[])
splitAt 0 [1,2,3] == ([],[1,2,3])
splitAt (-1) [1,2,3] == ([],[1,2,3])It is equivalent to ( when take n xs, drop n xs)n is not _|_
(splitAt _|_ xs = _|_).
splitAt is an instance of the more general genericSplitAt,
in which n may be of any integral type.
takeWhile :: (a -> Bool) -> [a] -> [a] Source #
takeWhile, applied to a predicate p and a list xs, returns the
longest prefix (possibly empty) of xs of elements that satisfy p:
takeWhile (< 3) [1,2,3,4,1,2,3,4] == [1,2] takeWhile (< 9) [1,2,3] == [1,2,3] takeWhile (< 0) [1,2,3] == []
span :: (a -> Bool) -> [a] -> ([a], [a]) Source #
span, applied to a predicate p and a list xs, returns a tuple where
first element is longest prefix (possibly empty) of xs of elements that
satisfy p and second element is the remainder of the list:
span (< 3) [1,2,3,4,1,2,3,4] == ([1,2],[3,4,1,2,3,4]) span (< 9) [1,2,3] == ([1,2,3],[]) span (< 0) [1,2,3] == ([],[1,2,3])
break :: (a -> Bool) -> [a] -> ([a], [a]) Source #
break, applied to a predicate p and a list xs, returns a tuple where
first element is longest prefix (possibly empty) of xs of elements that
do not satisfy p and second element is the remainder of the list:
break (> 3) [1,2,3,4,1,2,3,4] == ([1,2,3],[4,1,2,3,4]) break (< 9) [1,2,3] == ([],[1,2,3]) break (> 9) [1,2,3] == ([1,2,3],[])
Searching lists
lookup :: Eq a => a -> [(a, b)] -> Maybe b Source #
lookup key assocs looks up a key in an association list.
Zipping and unzipping lists
unzip :: [(a, b)] -> ([a], [b]) Source #
unzip transforms a list of pairs into a list of first components
and a list of second components.
Functions on strings
lines :: String -> [String] Source #
lines breaks a string up into a list of strings at newline
characters. The resulting strings do not contain newlines.
Note that after splitting the string at newline characters, the last part of the string is considered a line even if it doesn't end with a newline. For example,
>>>lines ""[]
>>>lines "\n"[""]
>>>lines "one"["one"]
>>>lines "one\n"["one"]
>>>lines "one\n\n"["one",""]
>>>lines "one\ntwo"["one","two"]
>>>lines "one\ntwo\n"["one","two"]
Thus contains at least as many elements as newlines in lines ss.
words :: String -> [String] Source #
words breaks a string up into a list of words, which were delimited
by white space.
>>>words "Lorem ipsum\ndolor"["Lorem","ipsum","dolor"]
Converting to and from String
Converting to String
Conversion of values to readable Strings.
Derived instances of Show have the following properties, which
are compatible with derived instances of Read:
- The result of
showis a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - If the constructor is defined to be an infix operator, then
showsPrecwill produce infix applications of the constructor. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
xis less thand(associativity is ignored). Thus, ifdis0then the result is never surrounded in parentheses; ifdis11it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined using record syntax, then
showwill produce the record-syntax form, with the fields given in the same order as the original declaration.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Show is equivalent to
instance (Show a) => Show (Tree a) where
showsPrec d (Leaf m) = showParen (d > app_prec) $
showString "Leaf " . showsPrec (app_prec+1) m
where app_prec = 10
showsPrec d (u :^: v) = showParen (d > up_prec) $
showsPrec (up_prec+1) u .
showString " :^: " .
showsPrec (up_prec+1) v
where up_prec = 5Note that right-associativity of :^: is ignored. For example,
produces the stringshow(Leaf 1 :^: Leaf 2 :^: Leaf 3)"Leaf 1 :^: (Leaf 2 :^: Leaf 3)".
Methods
Arguments
| :: Int | the operator precedence of the enclosing
context (a number from |
| -> a | the value to be converted to a |
| -> ShowS |
Convert a value to a readable String.
showsPrec should satisfy the law
showsPrec d x r ++ s == showsPrec d x (r ++ s)
Derived instances of Read and Show satisfy the following:
That is, readsPrec parses the string produced by
showsPrec, and delivers the value that showsPrec started with.
Instances
| Show Bool # | |
| Show Char # | Since: base-2.1 |
| Show Double # | Since: base-2.1 |
| Show Float # | Since: base-2.1 |
| Show Int # | Since: base-2.1 |
| Show Int8 # | Since: base-2.1 |
| Show Int16 # | Since: base-2.1 |
| Show Int32 # | Since: base-2.1 |
| Show Int64 # | Since: base-2.1 |
| Show Integer # | Since: base-2.1 |
| Show Natural # | Since: base-4.8.0.0 |
| Show Ordering # | |
| Show Word # | Since: base-2.1 |
| Show Word8 # | Since: base-2.1 |
| Show Word16 # | Since: base-2.1 |
| Show Word32 # | Since: base-2.1 |
| Show Word64 # | Since: base-2.1 |
| Show RuntimeRep # | |
| Show VecCount # | |
| Show VecElem # | |
| Show CallStack # | Since: base-4.9.0.0 |
| Show SomeTypeRep # | Since: base-4.10.0.0 |
Defined in Data.Typeable.Internal | |
| Show () # | |
| Show TyCon # | Since: base-2.1 |
| Show Module # | Since: base-4.9.0.0 |
| Show TrName # | Since: base-4.9.0.0 |
| Show KindRep # | |
| Show TypeLitSort # | |
| Show SrcLoc # | |
| Show SomeException # | Since: base-3.0 |
Defined in GHC.Exception | |
| Show GeneralCategory # | |
Defined in GHC.Unicode | |
| Show Number # | |
| Show Lexeme # | |
| Show Fingerprint # | Since: base-4.7.0.0 |
Defined in GHC.Fingerprint.Type | |
| Show IOMode # | |
| Show IntPtr # | |
| Show WordPtr # | |
| Show CUIntMax # | |
| Show CIntMax # | |
| Show CUIntPtr # | |
| Show CIntPtr # | |
| Show CSUSeconds # | |
Defined in Foreign.C.Types | |
| Show CUSeconds # | |
| Show CTime # | |
| Show CClock # | |
| Show CSigAtomic # | |
Defined in Foreign.C.Types | |
| Show CWchar # | |
| Show CSize # | |
| Show CPtrdiff # | |
| Show CDouble # | |
| Show CFloat # | |
| Show CBool # | |
| Show CULLong # | |
| Show CLLong # | |
| Show CULong # | |
| Show CLong # | |
| Show CUInt # | |
| Show CInt # | |
| Show CUShort # | |
| Show CShort # | |
| Show CUChar # | |
| Show CSChar # | |
| Show CChar # | |
| Show SomeNat # | Since: base-4.7.0.0 |
| Show SomeSymbol # | Since: base-4.7.0.0 |
Defined in GHC.TypeLits | |
| Show DecidedStrictness # | |
Defined in GHC.Generics | |
| Show SourceStrictness # | |
Defined in GHC.Generics | |
| Show SourceUnpackedness # | |
Defined in GHC.Generics | |
| Show Associativity # | |
Defined in GHC.Generics | |
| Show Fixity # | |
| Show Any # | |
| Show All # | |
| Show ArithException # | Since: base-4.0.0.0 |
Defined in GHC.Exception | |
| Show ErrorCall # | Since: base-4.0.0.0 |
| Show IOException # | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Show MaskingState # | |
| Show CodingProgress # | |
Defined in GHC.IO.Encoding.Types | |
| Show TextEncoding # | Since: base-4.3.0.0 |
Defined in GHC.IO.Encoding.Types | |
| Show SeekMode # | |
| Show NewlineMode # | |
Defined in GHC.IO.Handle.Types | |
| Show Newline # | |
| Show BufferMode # | |
Defined in GHC.IO.Handle.Types | |
| Show Handle # | Since: base-4.1.0.0 |
| Show IOErrorType # | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Show ExitCode # | |
| Show FixIOException # | Since: base-4.11.0.0 |
Defined in GHC.IO.Exception | |
| Show ArrayException # | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Show AsyncException # | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Show SomeAsyncException # | Since: base-4.7.0.0 |
Defined in GHC.IO.Exception | |
| Show AssertionFailed # | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Show CompactionFailed # | Since: base-4.10.0.0 |
Defined in GHC.IO.Exception | |
| Show AllocationLimitExceeded # | Since: base-4.7.1.0 |
Defined in GHC.IO.Exception | |
| Show Deadlock # | Since: base-4.1.0.0 |
| Show BlockedIndefinitelyOnSTM # | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Show BlockedIndefinitelyOnMVar # | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
| Show CodingFailureMode # | |
Defined in GHC.IO.Encoding.Failure | |
| Show Fd # | |
| Show CTimer # | |
| Show CKey # | |
| Show CId # | |
| Show CFsFilCnt # | |
| Show CFsBlkCnt # | |
| Show CClockId # | |
| Show CBlkCnt # | |
| Show CBlkSize # | |
| Show CRLim # | |
| Show CTcflag # | |
| Show CSpeed # | |
| Show CCc # | |
| Show CUid # | |
| Show CNlink # | |
| Show CGid # | |
| Show CSsize # | |
| Show CPid # | |
| Show COff # | |
| Show CMode # | |
| Show CIno # | |
| Show CDev # | |
| Show Lifetime # | |
| Show Event # | Since: base-4.3.1.0 |
| Show Dynamic # | Since: base-2.1 |
| Show ThreadStatus # | |
Defined in GHC.Conc.Sync | |
| Show BlockReason # | |
Defined in GHC.Conc.Sync | |
| Show ThreadId # | Since: base-4.2.0.0 |
| Show NestedAtomically # | Since: base-4.0 |
Defined in Control.Exception.Base | |
| Show NonTermination # | Since: base-4.0 |
Defined in Control.Exception.Base | |
| Show TypeError # | Since: base-4.9.0.0 |
| Show NoMethodError # | Since: base-4.0 |
Defined in Control.Exception.Base | |
| Show RecUpdError # | Since: base-4.0 |
Defined in Control.Exception.Base | |
| Show RecConError # | Since: base-4.0 |
Defined in Control.Exception.Base | |
| Show RecSelError # | Since: base-4.0 |
Defined in Control.Exception.Base | |
| Show PatternMatchFail # | Since: base-4.0 |
Defined in Control.Exception.Base | |
| Show FdKey # | |
| Show FileLockingNotSupported # | |
Defined in GHC.IO.Handle.Lock | |
| Show HandlePosn # | Since: base-4.1.0.0 |
Defined in GHC.IO.Handle | |
| Show Version # | |
| Show ByteOrder # | |
| Show GCDetails # | |
| Show RTSStats # | |
| Show RTSFlags # | |
| Show ParFlags # | |
| Show TickyFlags # | |
Defined in GHC.RTS.Flags | |
| Show TraceFlags # | |
Defined in GHC.RTS.Flags | |
| Show DoTrace # | |
| Show ProfFlags # | |
| Show DoHeapProfile # | |
Defined in GHC.RTS.Flags | |
| Show CCFlags # | |
| Show DoCostCentres # | |
Defined in GHC.RTS.Flags | |
| Show DebugFlags # | |
Defined in GHC.RTS.Flags | |
| Show MiscFlags # | |
| Show ConcFlags # | |
| Show GCFlags # | |
| Show GiveGCStats # | |
Defined in GHC.RTS.Flags | |
| Show Fixity # | |
| Show ConstrRep # | |
| Show DataRep # | |
| Show Constr # | Since: base-4.0.0.0 |
| Show DataType # | |
| Show StaticPtrInfo # | |
Defined in GHC.StaticPtr | |
| Show Void # | Since: base-4.8.0.0 |
| Show a => Show [a] # | Since: base-2.1 |
| Show a => Show (Maybe a) # | |
| Show a => Show (Ratio a) # | Since: base-2.0.1 |
| Show (Ptr a) # | Since: base-2.1 |
| Show (FunPtr a) # | Since: base-2.1 |
| Show p => Show (Par1 p) # | |
| Show a => Show (NonEmpty a) # | |
| Show a => Show (Down a) # | Since: base-4.7.0.0 |
| Show a => Show (Product a) # | |
| Show a => Show (Sum a) # | |
| Show a => Show (Dual a) # | |
| Show a => Show (Last a) # | |
| Show a => Show (First a) # | |
| Show (ForeignPtr a) # | Since: base-2.1 |
Defined in GHC.ForeignPtr | |
| Show a => Show (Identity a) # | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Show a => Show (ZipList a) # | |
| Show a => Show (Option a) # | |
| Show m => Show (WrappedMonoid m) # | |
Defined in Data.Semigroup | |
| Show a => Show (Last a) # | |
| Show a => Show (First a) # | |
| Show a => Show (Max a) # | |
| Show a => Show (Min a) # | |
| HasResolution a => Show (Fixed a) # | Since: base-2.1 |
| Show a => Show (Complex a) # | |
| Show (a -> b) # | Since: base-2.1 |
| (Show a, Show b) => Show (Either a b) # | |
| Show (V1 p) # | Since: base-4.9.0.0 |
| Show (U1 p) # | Since: base-4.9.0.0 |
| Show (TypeRep a) # | |
| (Show a, Show b) => Show (a, b) # | Since: base-2.1 |
| Show (ST s a) # | Since: base-2.1 |
| Show (Proxy s) # | Since: base-4.7.0.0 |
| (Show a, Show b) => Show (Arg a b) # | |
| Show (f p) => Show (Rec1 f p) # | |
| Show (URec Word p) # | |
| Show (URec Int p) # | |
| Show (URec Float p) # | |
| Show (URec Double p) # | |
| Show (URec Char p) # | |
| (Show a, Show b, Show c) => Show (a, b, c) # | Since: base-2.1 |
| Show (a :~: b) # | |
| Show (Coercion a b) # | |
| Show (f a) => Show (Alt f a) # | |
| Show a => Show (Const a b) # | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Show c => Show (K1 i c p) # | |
| (Show (f p), Show (g p)) => Show ((f :+: g) p) # | |
| (Show (f p), Show (g p)) => Show ((f :*: g) p) # | |
| (Show a, Show b, Show c, Show d) => Show (a, b, c, d) # | Since: base-2.1 |
| Show (a :~~: b) # | Since: base-4.10.0.0 |
| (Show1 f, Show1 g, Show a) => Show (Sum f g a) # | Since: base-4.9.0.0 |
| (Show1 f, Show1 g, Show a) => Show (Product f g a) # | Since: base-4.9.0.0 |
| Show (f p) => Show (M1 i c f p) # | |
| Show (f (g p)) => Show ((f :.: g) p) # | |
| (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) # | Since: base-2.1 |
| (Show1 f, Show1 g, Show a) => Show (Compose f g a) # | Since: base-4.9.0.0 |
| (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a, b, c, d, e, f) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g) => Show (a, b, c, d, e, f, g) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h) => Show (a, b, c, d, e, f, g, h) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i) => Show (a, b, c, d, e, f, g, h, i) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j) => Show (a, b, c, d, e, f, g, h, i, j) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k) => Show (a, b, c, d, e, f, g, h, i, j, k) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l) => Show (a, b, c, d, e, f, g, h, i, j, k, l) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # | Since: base-2.1 |
| (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k, Show l, Show m, Show n, Show o) => Show (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # | Since: base-2.1 |
showChar :: Char -> ShowS Source #
utility function converting a Char to a show function that
simply prepends the character unchanged.
showString :: String -> ShowS Source #
utility function converting a String to a show function that
simply prepends the string unchanged.
Converting from String
Parsing of Strings, producing values.
Derived instances of Read make the following assumptions, which
derived instances of Show obey:
- If the constructor is defined to be an infix operator, then the
derived
Readinstance will parse only infix applications of the constructor (not the prefix form). - Associativity is not used to reduce the occurrence of parentheses, although precedence may be.
- If the constructor is defined using record syntax, the derived
Readwill parse only the record-syntax form, and furthermore, the fields must be given in the same order as the original declaration. - The derived
Readinstance allows arbitrary Haskell whitespace between tokens of the input string. Extra parentheses are also allowed.
For example, given the declarations
infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a
the derived instance of Read in Haskell 2010 is equivalent to
instance (Read a) => Read (Tree a) where
readsPrec d r = readParen (d > app_prec)
(\r -> [(Leaf m,t) |
("Leaf",s) <- lex r,
(m,t) <- readsPrec (app_prec+1) s]) r
++ readParen (d > up_prec)
(\r -> [(u:^:v,w) |
(u,s) <- readsPrec (up_prec+1) r,
(":^:",t) <- lex s,
(v,w) <- readsPrec (up_prec+1) t]) r
where app_prec = 10
up_prec = 5Note that right-associativity of :^: is unused.
The derived instance in GHC is equivalent to
instance (Read a) => Read (Tree a) where
readPrec = parens $ (prec app_prec $ do
Ident "Leaf" <- lexP
m <- step readPrec
return (Leaf m))
+++ (prec up_prec $ do
u <- step readPrec
Symbol ":^:" <- lexP
v <- step readPrec
return (u :^: v))
where app_prec = 10
up_prec = 5
readListPrec = readListPrecDefaultWhy do both readsPrec and readPrec exist, and why does GHC opt to
implement readPrec in derived Read instances instead of readsPrec?
The reason is that readsPrec is based on the ReadS type, and although
ReadS is mentioned in the Haskell 2010 Report, it is not a very efficient
parser data structure.
readPrec, on the other hand, is based on a much more efficient ReadPrec
datatype (a.k.a "new-style parsers"), but its definition relies on the use
of the RankNTypes language extension. Therefore, readPrec (and its
cousin, readListPrec) are marked as GHC-only. Nevertheless, it is
recommended to use readPrec instead of readsPrec whenever possible
for the efficiency improvements it brings.
As mentioned above, derived Read instances in GHC will implement
readPrec instead of readsPrec. The default implementations of
readsPrec (and its cousin, readList) will simply use readPrec under
the hood. If you are writing a Read instance by hand, it is recommended
to write it like so:
instanceReadT wherereadPrec= ...readListPrec=readListPrecDefault
Methods
Arguments
| :: Int | the operator precedence of the enclosing
context (a number from |
| -> ReadS a |
attempts to parse a value from the front of the string, returning a list of (parsed value, remaining string) pairs. If there is no successful parse, the returned list is empty.
Derived instances of Read and Show satisfy the following:
That is, readsPrec parses the string produced by
showsPrec, and delivers the value that
showsPrec started with.
Instances
| Read Bool # | Since: base-2.1 |
| Read Char # | Since: base-2.1 |
| Read Double # | Since: base-2.1 |
| Read Float # | Since: base-2.1 |
| Read Int # | Since: base-2.1 |
| Read Int8 # | Since: base-2.1 |
| Read Int16 # | Since: base-2.1 |
| Read Int32 # | Since: base-2.1 |
| Read Int64 # | Since: base-2.1 |
| Read Integer # | Since: base-2.1 |
| Read Natural # | Since: base-4.8.0.0 |
| Read Ordering # | Since: base-2.1 |
| Read Word # | Since: base-4.5.0.0 |
| Read Word8 # | Since: base-2.1 |
| Read Word16 # | Since: base-2.1 |
| Read Word32 # | Since: base-2.1 |
| Read Word64 # | Since: base-2.1 |
| Read () # | Since: base-2.1 |
| Read GeneralCategory # | |
| Read Lexeme # | Since: base-2.1 |
| Read IOMode # | |
| Read IntPtr # | |
| Read WordPtr # | |
| Read CUIntMax # | |
| Read CIntMax # | |
| Read CUIntPtr # | |
| Read CIntPtr # | |
| Read CSUSeconds # | |
Defined in Foreign.C.Types | |
| Read CUSeconds # | |
| Read CTime # | |
| Read CClock # | |
| Read CSigAtomic # | |
Defined in Foreign.C.Types | |
| Read CWchar # | |
| Read CSize # | |
| Read CPtrdiff # | |
| Read CDouble # | |
| Read CFloat # | |
| Read CBool # | |
| Read CULLong # | |
| Read CLLong # | |
| Read CULong # | |
| Read CLong # | |
| Read CUInt # | |
| Read CInt # | |
| Read CUShort # | |
| Read CShort # | |
| Read CUChar # | |
| Read CSChar # | |
| Read CChar # | |
| Read SomeNat # | Since: base-4.7.0.0 |
| Read SomeSymbol # | Since: base-4.7.0.0 |
Defined in GHC.TypeLits | |
| Read DecidedStrictness # | |
Defined in GHC.Generics | |
| Read SourceStrictness # | |
Defined in GHC.Generics | |
| Read SourceUnpackedness # | |
Defined in GHC.Generics | |
| Read Associativity # | |
Defined in GHC.Generics | |
| Read Fixity # | |
| Read Any # | |
| Read All # | |
| Read SeekMode # | |
| Read NewlineMode # | |
Defined in GHC.IO.Handle.Types | |
| Read Newline # | |
| Read BufferMode # | |
Defined in GHC.IO.Handle.Types | |
| Read ExitCode # | |
| Read Fd # | |
| Read CKey # | |
| Read CId # | |
| Read CFsFilCnt # | |
| Read CFsBlkCnt # | |
| Read CClockId # | |
| Read CBlkCnt # | |
| Read CBlkSize # | |
| Read CRLim # | |
| Read CTcflag # | |
| Read CSpeed # | |
| Read CCc # | |
| Read CUid # | |
| Read CNlink # | |
| Read CGid # | |
| Read CSsize # | |
| Read CPid # | |
| Read COff # | |
| Read CMode # | |
| Read CIno # | |
| Read CDev # | |
| Read Version # | |
| Read ByteOrder # | |
| Read GCDetails # | |
| Read RTSStats # | |
| Read Void # | Reading a Since: base-4.8.0.0 |
| Read a => Read [a] # | Since: base-2.1 |
| Read a => Read (Maybe a) # | Since: base-2.1 |
| (Integral a, Read a) => Read (Ratio a) # | Since: base-2.1 |
| Read p => Read (Par1 p) # | |
| Read a => Read (NonEmpty a) # | |
| Read a => Read (Down a) # | Since: base-4.7.0.0 |
| Read a => Read (Product a) # | |
| Read a => Read (Sum a) # | |
| Read a => Read (Dual a) # | |
| Read a => Read (Last a) # | |
| Read a => Read (First a) # | |
| Read a => Read (Identity a) # | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Read a => Read (ZipList a) # | |
| Read a => Read (Option a) # | |
| Read m => Read (WrappedMonoid m) # | |
Defined in Data.Semigroup Methods readsPrec :: Int -> ReadS (WrappedMonoid m) Source # readList :: ReadS [WrappedMonoid m] Source # readPrec :: ReadPrec (WrappedMonoid m) Source # readListPrec :: ReadPrec [WrappedMonoid m] Source # | |
| Read a => Read (Last a) # | |
| Read a => Read (First a) # | |
| Read a => Read (Max a) # | |
| Read a => Read (Min a) # | |
| HasResolution a => Read (Fixed a) # | Since: base-4.3.0.0 |
| Read a => Read (Complex a) # | |
| (Read a, Read b) => Read (Either a b) # | |
| Read (V1 p) # | Since: base-4.9.0.0 |
| Read (U1 p) # | Since: base-4.9.0.0 |
| (Read a, Read b) => Read (a, b) # | Since: base-2.1 |
| Read (Proxy t) # | Since: base-4.7.0.0 |
| (Read a, Read b) => Read (Arg a b) # | |
| Read (f p) => Read (Rec1 f p) # | |
| (Read a, Read b, Read c) => Read (a, b, c) # | Since: base-2.1 |
| a ~ b => Read (a :~: b) # | Since: base-4.7.0.0 |
| Coercible a b => Read (Coercion a b) # | Since: base-4.7.0.0 |
| Read (f a) => Read (Alt f a) # | |
| Read a => Read (Const a b) # | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Read c => Read (K1 i c p) # | |
| (Read (f p), Read (g p)) => Read ((f :+: g) p) # | |
| (Read (f p), Read (g p)) => Read ((f :*: g) p) # | |
| (Read a, Read b, Read c, Read d) => Read (a, b, c, d) # | Since: base-2.1 |
| a ~~ b => Read (a :~~: b) # | Since: base-4.10.0.0 |
| (Read1 f, Read1 g, Read a) => Read (Sum f g a) # | Since: base-4.9.0.0 |
| (Read1 f, Read1 g, Read a) => Read (Product f g a) # | Since: base-4.9.0.0 |
| Read (f p) => Read (M1 i c f p) # | |
| Read (f (g p)) => Read ((f :.: g) p) # | |
| (Read a, Read b, Read c, Read d, Read e) => Read (a, b, c, d, e) # | Since: base-2.1 |
| (Read1 f, Read1 g, Read a) => Read (Compose f g a) # | Since: base-4.9.0.0 |
| (Read a, Read b, Read c, Read d, Read e, Read f) => Read (a, b, c, d, e, f) # | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g) => Read (a, b, c, d, e, f, g) # | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h) => Read (a, b, c, d, e, f, g, h) # | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i) => Read (a, b, c, d, e, f, g, h, i) # | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j) => Read (a, b, c, d, e, f, g, h, i, j) # | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k) => Read (a, b, c, d, e, f, g, h, i, j, k) # | Since: base-2.1 |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l) => Read (a, b, c, d, e, f, g, h, i, j, k, l) # | Since: base-2.1 |
Defined in GHC.Read | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m) # | Since: base-2.1 |
Defined in GHC.Read | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # | Since: base-2.1 |
Defined in GHC.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] Source # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] Source # | |
| (Read a, Read b, Read c, Read d, Read e, Read f, Read g, Read h, Read i, Read j, Read k, Read l, Read m, Read n, Read o) => Read (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # | Since: base-2.1 |
Defined in GHC.Read Methods readsPrec :: Int -> ReadS (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # readList :: ReadS [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] Source # readPrec :: ReadPrec (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # readListPrec :: ReadPrec [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] Source # | |
read :: Read a => String -> a Source #
The read function reads input from a string, which must be
completely consumed by the input process. read fails with an error if the
parse is unsuccessful, and it is therefore discouraged from being used in
real applications. Use readMaybe or readEither for safe alternatives.
>>>read "123" :: Int123
>>>read "hello" :: Int*** Exception: Prelude.read: no parse
The lex function reads a single lexeme from the input, discarding
initial white space, and returning the characters that constitute the
lexeme. If the input string contains only white space, lex returns a
single successful `lexeme' consisting of the empty string. (Thus
.) If there is no legal lexeme at the
beginning of the input string, lex "" = [("","")]lex fails (i.e. returns []).
This lexer is not completely faithful to the Haskell lexical syntax in the following respects:
- Qualified names are not handled properly
- Octal and hexadecimal numerics are not recognized as a single token
- Comments are not treated properly
Basic Input and output
A value of type is a computation which, when performed,
does some I/O before returning a value of type IO aa.
There is really only one way to "perform" an I/O action: bind it to
Main.main in your program. When your program is run, the I/O will
be performed. It isn't possible to perform I/O from an arbitrary
function, unless that function is itself in the IO monad and called
at some point, directly or indirectly, from Main.main.
IO is a monad, so IO actions can be combined using either the do-notation
or the >> and >>= operations from the Monad class.
Instances
| Monad IO # | Since: base-2.1 |
| Functor IO # | Since: base-2.1 |
| MonadFix IO # | Since: base-2.1 |
| MonadFail IO # | Since: base-4.9.0.0 |
| Applicative IO # | Since: base-2.1 |
| MonadPlus IO # | Since: base-4.9.0.0 |
| Alternative IO # | Since: base-4.9.0.0 |
| MonadIO IO # | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (IO a) # | Since: base-4.10.0.0 |
| Monoid a => Monoid (IO a) # | Since: base-4.9.0.0 |
| a ~ () => HPrintfType (IO a) # | Since: base-4.7.0.0 |
Defined in Text.Printf | |
| a ~ () => PrintfType (IO a) # | Since: base-4.7.0.0 |
Defined in Text.Printf | |
Simple I/O operations
Output functions
print :: Show a => a -> IO () Source #
The print function outputs a value of any printable type to the
standard output device.
Printable types are those that are instances of class Show; print
converts values to strings for output using the show operation and
adds a newline.
For example, a program to print the first 20 integers and their powers of 2 could be written as:
main = print ([(n, 2^n) | n <- [0..19]])
Input functions
getContents :: IO String Source #
The getContents operation returns all user input as a single string,
which is read lazily as it is needed
(same as hGetContents stdin).
interact :: (String -> String) -> IO () Source #
The interact function takes a function of type String->String
as its argument. The entire input from the standard input device is
passed to this function as its argument, and the resulting string is
output on the standard output device.
Files
type FilePath = String Source #
File and directory names are values of type String, whose precise
meaning is operating system dependent. Files can be opened, yielding a
handle which can then be used to operate on the contents of that file.
readFile :: FilePath -> IO String Source #
The readFile function reads a file and
returns the contents of the file as a string.
The file is read lazily, on demand, as with getContents.
writeFile :: FilePath -> String -> IO () Source #
The computation writeFile file str function writes the string str,
to the file file.
appendFile :: FilePath -> String -> IO () Source #
The computation appendFile file str function appends the string str,
to the file file.
Note that writeFile and appendFile write a literal string
to a file. To write a value of any printable type, as with print,
use the show function to convert the value to a string first.
main = appendFile "squares" (show [(x,x*x) | x <- [0,0.1..2]])
Exception handling in the I/O monad
type IOError = IOException Source #