| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Incipit.Base
Description
Reexports from base.
Synopsis
- class Functor f => Applicative (f :: Type -> Type) where
- class Applicative f => Alternative (f :: Type -> Type) where
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- optional :: Alternative f => f a -> f (Maybe a)
- newtype Const a (b :: k) = Const {
- getConst :: a
- newtype ZipList a = ZipList {
- getZipList :: [a]
- (&&&) :: Arrow a => a b c -> a b c' -> a b (c, c')
- (>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c
- (<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c
- module Control.Concurrent.MVar
- data SomeException = (Exception e, HasExceptionContext) => SomeException e
- class (Typeable e, Show e) => Exception e
- class Applicative m => Monad (m :: Type -> Type) where
- guard :: Alternative f => Bool -> f ()
- join :: Monad m => m (m a) -> m a
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- when :: Applicative f => Bool -> f () -> f ()
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- forever :: Applicative f => f a -> f b
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- replicateM_ :: Applicative m => Int -> m a -> m ()
- unless :: Applicative f => Bool -> f () -> f ()
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- module Control.Monad.Fail
- module Control.Monad.IO.Class
- module Data.Bifunctor
- xor :: Bits a => a -> a -> a
- toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b
- module Data.Bool
- data Char
- chr :: Int -> Char
- module Data.Coerce
- module Data.Either
- module Data.Eq
- const :: a -> b -> a
- ($) :: (a -> b) -> a -> b
- id :: a -> a
- (.) :: (b -> c) -> (a -> b) -> a -> c
- flip :: (a -> b -> c) -> b -> a -> c
- fix :: (a -> a) -> a
- on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
- (&) :: a -> (a -> b) -> b
- class Functor (f :: Type -> Type) where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- ($>) :: Functor f => f a -> b -> f b
- void :: Functor f => f a -> f ()
- module Data.Functor.Compose
- class Contravariant (f :: Type -> Type) where
- (>$<) :: Contravariant f => (a -> b) -> f b -> f a
- module Data.Functor.Identity
- module Data.Int
- type Type = TYPE LiftedRep
- type Constraint = CONSTRAINT LiftedRep
- unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- transpose :: [[a]] -> [[a]]
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- (++) :: [a] -> [a] -> [a]
- filter :: (a -> Bool) -> [a] -> [a]
- zip :: [a] -> [b] -> [(a, b)]
- map :: (a -> b) -> [a] -> [b]
- uncons :: [a] -> Maybe (a, [a])
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
- scanl1 :: (a -> a -> a) -> [a] -> [a]
- scanl' :: (b -> a -> b) -> b -> [a] -> [b]
- 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]
- takeWhile :: (a -> Bool) -> [a] -> [a]
- dropWhile :: (a -> Bool) -> [a] -> [a]
- take :: Int -> [a] -> [a]
- drop :: Int -> [a] -> [a]
- splitAt :: Int -> [a] -> ([a], [a])
- span :: (a -> Bool) -> [a] -> ([a], [a])
- break :: (a -> Bool) -> [a] -> ([a], [a])
- reverse :: [a] -> [a]
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- unzip :: [(a, b)] -> ([a], [b])
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- isPrefixOf :: Eq a => [a] -> [a] -> Bool
- intersperse :: a -> [a] -> [a]
- intercalate :: [a] -> [[a]] -> [a]
- genericLength :: Num i => [a] -> i
- genericTake :: Integral i => i -> [a] -> [a]
- genericDrop :: Integral i => i -> [a] -> [a]
- genericSplitAt :: Integral i => i -> [a] -> ([a], [a])
- genericReplicate :: Integral i => i -> a -> [a]
- group :: Eq a => [a] -> [[a]]
- inits :: [a] -> [[a]]
- tails :: [a] -> [[a]]
- subsequences :: [a] -> [[a]]
- permutations :: [a] -> [[a]]
- sort :: Ord a => [a] -> [a]
- data NonEmpty a = a :| [a]
- nonEmpty :: [a] -> Maybe (NonEmpty a)
- data Maybe a
- maybe :: b -> (a -> b) -> Maybe a -> b
- isJust :: Maybe a -> Bool
- isNothing :: Maybe a -> Bool
- fromMaybe :: a -> Maybe a -> a
- maybeToList :: Maybe a -> [a]
- listToMaybe :: [a] -> Maybe a
- catMaybes :: [Maybe a] -> [a]
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- class Semigroup a => Monoid a where
- data Ordering
- class Eq a => Ord a where
- newtype Down a = Down {
- getDown :: a
- comparing :: Ord a => (b -> a) -> b -> b -> Ordering
- data Proxy (t :: k) = Proxy
- class Semigroup a where
- class (Functor t, Foldable t) => Traversable (t :: Type -> Type) where
- traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
- sequenceA :: Applicative f => t (f a) -> f (t a)
- mapM :: Monad m => (a -> m b) -> t a -> m (t b)
- sequence :: Monad m => t (m a) -> m (t a)
- for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- mapAccumL :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)
- mapAccumR :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)
- fst :: (a, b) -> a
- snd :: (a, b) -> b
- curry :: ((a, b) -> c) -> a -> b -> c
- uncurry :: (a -> b -> c) -> (a, b) -> c
- swap :: (a, b) -> (b, a)
- class Typeable (a :: k)
- class a ~# b => (a :: k) ~ (b :: k)
- data Void
- data Word8
- data Word
- data Word64
- data Word32
- data Word16
- seq :: a -> b -> b
- ord :: Char -> Int
- minInt :: Int
- maxInt :: Int
- ($!) :: (a -> b) -> a -> b
- class Enum a where
- succ :: a -> a
- pred :: a -> a
- toEnum :: Int -> a
- fromEnum :: a -> Int
- enumFrom :: a -> [a]
- enumFromThen :: a -> a -> [a]
- enumFromTo :: a -> a -> [a]
- enumFromThenTo :: a -> a -> a -> [a]
- class Bounded a where
- error :: HasCallStack => [Char] -> a
- undefined :: HasCallStack => a
- data Float = F# Float#
- data Double = D# Double#
- class Generic a
- data Integer
- class Num a where
- subtract :: Num a => a -> a -> a
- module GHC.OverloadedLabels
- class Num a => Fractional a where
- fromRational :: Rational -> a
- fromIntegral :: (Integral a, Num b) => a -> b
- realToFrac :: (Real a, Fractional b) => a -> b
- class (Real a, Enum a) => Integral a where
- class (Num a, Ord a) => Real a where
- toRational :: a -> Rational
- class (Real a, Fractional a) => RealFrac a where
- data Ratio a
- type Rational = Ratio Integer
- (^) :: (Num a, Integral b) => a -> b -> a
- numerator :: Ratio a -> a
- denominator :: Ratio a -> a
- even :: Integral a => a -> Bool
- odd :: Integral a => a -> Bool
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- class Show a
- type HasCallStack = ?callStack :: CallStack
- withFrozenCallStack :: HasCallStack => (HasCallStack => a) -> a
- data Symbol
- data Natural
- type family (a :: Natural) - (b :: Natural) :: Natural where ...
- class KnownNat (n :: Nat) where
- class KnownSymbol (n :: Symbol) where
- symbolSing :: SSymbol n
- class KnownChar (n :: Char) where
- type family TypeError (a :: ErrorMessage) :: b where ...
- type family AppendSymbol (a :: Symbol) (b :: Symbol) :: Symbol where ...
- type family (a :: Natural) + (b :: Natural) :: Natural where ...
- type family (a :: Natural) * (b :: Natural) :: Natural where ...
- type family (a :: Natural) ^ (b :: Natural) :: Natural where ...
- type family CmpSymbol (a :: Symbol) (b :: Symbol) :: Ordering where ...
- type family CmpNat (a :: Natural) (b :: Natural) :: Ordering where ...
- type family CmpChar (a :: Char) (b :: Char) :: Ordering where ...
- type family Div (a :: Natural) (b :: Natural) :: Natural where ...
- type family Mod (a :: Natural) (b :: Natural) :: Natural where ...
- type family Log2 (a :: Natural) :: Natural where ...
- type family ConsSymbol (a :: Char) (b :: Symbol) :: Symbol where ...
- type family UnconsSymbol (a :: Symbol) :: Maybe (Char, Symbol) where ...
- type family CharToNat (a :: Char) :: Natural where ...
- type family NatToChar (a :: Natural) :: Char where ...
- pattern (:<>:) :: ErrorMessage -> ErrorMessage -> ErrorMessage
- pattern (:$$:) :: ErrorMessage -> ErrorMessage -> ErrorMessage
- pattern ShowType :: t -> ErrorMessage
- type (<=) (x :: t) (y :: t) = Assert (x <=? y) (LeErrMsg x y :: Constraint)
- type (<=?) (m :: k) (n :: k) = OrdCond (Compare m n) 'True 'True 'False
- data OrderingI (a :: k) (b :: k) where
- data SNat (n :: Nat)
- pattern SNat :: () => KnownNat n => SNat n
- data SomeNat = KnownNat n => SomeNat (Proxy n)
- type Nat = Natural
- natVal :: forall (n :: Nat) proxy. KnownNat n => proxy n -> Integer
- natVal' :: forall (n :: Nat). KnownNat n => Proxy# n -> Integer
- someNatVal :: Integer -> Maybe SomeNat
- sameNat :: forall (a :: Nat) (b :: Nat) proxy1 proxy2. (KnownNat a, KnownNat b) => proxy1 a -> proxy2 b -> Maybe (a :~: b)
- decideNat :: forall (a :: Nat) (b :: Nat) proxy1 proxy2. (KnownNat a, KnownNat b) => proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b)
- cmpNat :: forall (a :: Nat) (b :: Nat) proxy1 proxy2. (KnownNat a, KnownNat b) => proxy1 a -> proxy2 b -> OrderingI a b
- fromSNat :: forall (n :: Nat). SNat n -> Integer
- withKnownNat :: forall (n :: Nat) r. SNat n -> (KnownNat n => r) -> r
- withSomeSNat :: Integer -> (forall (n :: Nat). Maybe (SNat n) -> r) -> r
- data SChar (s :: Char)
- pattern SChar :: () => KnownChar c => SChar c
- data SSymbol (s :: Symbol)
- pattern SSymbol :: () => KnownSymbol s => SSymbol s
- data SomeChar = KnownChar n => SomeChar (Proxy n)
- data SomeSymbol = KnownSymbol n => SomeSymbol (Proxy n)
- symbolVal :: forall (n :: Symbol) proxy. KnownSymbol n => proxy n -> String
- symbolVal' :: forall (n :: Symbol). KnownSymbol n => Proxy# n -> String
- charVal :: forall (n :: Char) proxy. KnownChar n => proxy n -> Char
- charVal' :: forall (n :: Char). KnownChar n => Proxy# n -> Char
- someSymbolVal :: String -> SomeSymbol
- someCharVal :: Char -> SomeChar
- sameSymbol :: forall (a :: Symbol) (b :: Symbol) proxy1 proxy2. (KnownSymbol a, KnownSymbol b) => proxy1 a -> proxy2 b -> Maybe (a :~: b)
- decideSymbol :: forall (a :: Symbol) (b :: Symbol) proxy1 proxy2. (KnownSymbol a, KnownSymbol b) => proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b)
- sameChar :: forall (a :: Char) (b :: Char) proxy1 proxy2. (KnownChar a, KnownChar b) => proxy1 a -> proxy2 b -> Maybe (a :~: b)
- decideChar :: forall (a :: Char) (b :: Char) proxy1 proxy2. (KnownChar a, KnownChar b) => proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b)
- cmpSymbol :: forall (a :: Symbol) (b :: Symbol) proxy1 proxy2. (KnownSymbol a, KnownSymbol b) => proxy1 a -> proxy2 b -> OrderingI a b
- cmpChar :: forall (a :: Char) (b :: Char) proxy1 proxy2. (KnownChar a, KnownChar b) => proxy1 a -> proxy2 b -> OrderingI a b
- fromSSymbol :: forall (s :: Symbol). SSymbol s -> String
- withKnownSymbol :: forall (s :: Symbol) r. SSymbol s -> (KnownSymbol s => r) -> r
- withSomeSSymbol :: String -> (forall (s :: Symbol). SSymbol s -> r) -> r
- fromSChar :: forall (c :: Char). SChar c -> Char
- withKnownChar :: forall (c :: Char) r. SChar c -> (KnownChar c => r) -> r
- withSomeSChar :: Char -> (forall (c :: Char). SChar c -> r) -> r
- module Incipit.Fixed
- module Incipit.Foldable
- module Incipit.Fractional
- quot :: Integral a => a -> a -> Maybe a
- rem :: Integral a => a -> a -> Maybe a
- div :: Integral a => a -> a -> Maybe a
- mod :: Integral a => a -> a -> Maybe a
- quotRem :: Integral a => a -> a -> Maybe (a, a)
- divMod :: Integral a => a -> a -> Maybe (a, a)
- data Natural
- data IO a
- print :: Show a => a -> IO ()
- type FilePath = String
- putStr :: String -> IO ()
- putStrLn :: String -> IO ()
- showsPrec :: Show a => Int -> a -> ShowS
- showString :: String -> ShowS
- showParen :: Bool -> ShowS -> ShowS
Documentation
class Functor f => Applicative (f :: Type -> Type) where #
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 into the Structure.
Examples
>>>pure 1 :: Maybe IntJust 1
>>>pure 'z' :: [Char]"z"
>>>pure (pure ":D") :: Maybe [String]Just [":D"]
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*> that is more
efficient than the default one.
Example
Used in combination with , (<$>) can be used to build a record.(<*>)
>>>data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
>>>produceFoo :: Applicative f => f Foo>>>produceBar :: Applicative f => f Bar>>>produceBaz :: Applicative f => f Baz
>>>mkState :: Applicative f => f MyState>>>mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2 that is more
efficient than the default one. In particular, if fmap is an
expensive operation, it is likely better to use liftA2 than to
fmap over the structure and then use <*>.
This became a typeclass method in 4.10.0.0. Prior to that, it was
a function defined in terms of <*> and fmap.
Example
>>>liftA2 (,) (Just 3) (Just 5)Just (3,5)
>>>liftA2 (+) [1, 2, 3] [4, 5, 6][5,6,7,6,7,8,7,8,9]
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
Examples
If used in conjunction with the Applicative instance for Maybe,
you can chain Maybe computations, with a possible "early return"
in case of Nothing.
>>>Just 2 *> Just 3Just 3
>>>Nothing *> Just 3Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>>import Data.Char>>>import GHC.Internal.Text.ParserCombinators.ReadP>>>let p = string "my name is " *> munch1 isAlpha <* eof>>>readP_to_S p "my name is Simon"[("Simon","")]
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
| Applicative Complex | Since: base-4.9.0.0 |
| Applicative First | Since: base-4.9.0.0 |
| Applicative Last | Since: base-4.9.0.0 |
| Applicative Max | Since: base-4.9.0.0 |
| Applicative Min | Since: base-4.9.0.0 |
| Applicative Put | |
| Applicative Seq | Since: containers-0.5.4 |
| Applicative Tree | |
| Applicative NonEmpty | Since: base-4.9.0.0 |
| Applicative Identity | Since: base-4.8.0.0 |
| Applicative Down | Since: base-4.11.0.0 |
| 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 |
| Applicative Par1 | Since: base-4.9.0.0 |
| Applicative P | Since: base-4.5.0.0 |
| Applicative ReadP | Since: base-4.6.0.0 |
| Applicative IO | Since: base-2.1 |
| Applicative Maybe | Since: base-2.1 |
| Applicative Solo | Since: base-4.15 |
| Applicative [] | Since: base-2.1 |
| Monad m => Applicative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a -> WrappedMonad m a # (<*>) :: WrappedMonad m (a -> b) -> WrappedMonad m a -> WrappedMonad m b # liftA2 :: (a -> b -> c) -> WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m c # (*>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # (<*) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m a # | |
| Applicative (SetM s) | |
| Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in GHC.Internal.Control.Arrow Methods pure :: a0 -> ArrowMonad a a0 # (<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c # (*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # (<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
| Applicative (Either e) | Since: base-3.0 |
| Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Applicative (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Applicative (IParser t) | |
| Monoid a => Applicative ((,) a) | For tuples, the ("hello ", (+15)) <*> ("world!", 2002)
("hello world!",2017)Since: base-2.1 |
| Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
| (Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMissing f x a # (<*>) :: WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b # liftA2 :: (a -> b -> c) -> WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x c # (*>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # (<*) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x a # | |
| Applicative m => Applicative (Kleisli m a) | Since: base-4.14.0.0 |
Defined in GHC.Internal.Control.Arrow | |
| Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
| (Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f) | Since: base-4.17.0.0 |
Defined in GHC.Internal.Generics Methods pure :: a -> Generically1 f a # (<*>) :: Generically1 f (a -> b) -> Generically1 f a -> Generically1 f b # liftA2 :: (a -> b -> c) -> Generically1 f a -> Generically1 f b -> Generically1 f c # (*>) :: Generically1 f a -> Generically1 f b -> Generically1 f b # (<*) :: Generically1 f a -> Generically1 f b -> Generically1 f a # | |
| Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
| (Monoid a, Monoid b) => Applicative ((,,) a b) | Since: base-4.14.0.0 |
| (Applicative f, Applicative g) => Applicative (Product f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Product | |
| (Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods pure :: a -> WhenMatched f x y a # (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b # liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c # (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a # | |
| (Applicative f, Monad f) => Applicative (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods pure :: a -> WhenMissing f k x a # (<*>) :: WhenMissing f k x (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b # liftA2 :: (a -> b -> c) -> WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x c # (*>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # (<*) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x a # | |
| (Applicative f, Applicative g) => Applicative (f :*: g) | Since: base-4.9.0.0 |
| Monoid c => Applicative (K1 i c :: Type -> Type) | Since: base-4.12.0.0 |
| (Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) | Since: base-4.14.0.0 |
Defined in GHC.Internal.Base | |
| Applicative ((->) r) | Since: base-2.1 |
| (Applicative f, Applicative g) => Applicative (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
| (Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods pure :: a -> WhenMatched f k x y a # (<*>) :: WhenMatched f k x y (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b # liftA2 :: (a -> b -> c) -> WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y c # (*>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # (<*) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y a # | |
| (Applicative f, Applicative g) => Applicative (f :.: g) | Since: base-4.9.0.0 |
| Applicative f => Applicative (M1 i c f) | Since: base-4.9.0.0 |
class Applicative f => Alternative (f :: Type -> Type) where #
A monoid on applicative functors.
If defined, some and many should be the least solutions
of the equations:
Examples
>>>Nothing <|> Just 42Just 42
>>>[1, 2] <|> [3, 4][1,2,3,4]
>>>empty <|> print (2^15)32768
Methods
The identity of <|>
empty <|> a == a a <|> empty == a
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Examples
>>>some (putStr "la")lalalalalalalalala... * goes on forever *
>>>some Nothingnothing
>>>take 5 <$> some (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case some parser will attempt to
parse parser one or more times until it fails.
Zero or more.
Examples
>>>many (putStr "la")lalalalalalalalala... * goes on forever *
>>>many NothingJust []
>>>take 5 <$> many (Just 1)* hangs forever *
Note that this function can be used with Parsers based on
Applicatives. In that case many parser will attempt to
parse parser zero or more times until it fails.
Instances
| Alternative Seq | Since: containers-0.5.4 |
| Alternative ZipList | Since: base-4.11.0.0 |
| Alternative P | Since: base-4.5.0.0 |
| Alternative ReadP | Since: base-4.6.0.0 |
| Alternative IO | Takes the first non-throwing Since: base-4.9.0.0 |
| Alternative Maybe | Picks the leftmost Since: base-2.1 |
| Alternative [] | Combines lists by concatenation, starting from the empty list. Since: base-2.1 |
| MonadPlus m => Alternative (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative Methods empty :: WrappedMonad m a # (<|>) :: WrappedMonad m a -> WrappedMonad m a -> WrappedMonad m a # some :: WrappedMonad m a -> WrappedMonad m [a] # many :: WrappedMonad m a -> WrappedMonad m [a] # | |
| ArrowPlus a => Alternative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in GHC.Internal.Control.Arrow Methods empty :: ArrowMonad a a0 # (<|>) :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 # some :: ArrowMonad a a0 -> ArrowMonad a [a0] # many :: ArrowMonad a a0 -> ArrowMonad a [a0] # | |
| Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| Alternative (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| (ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods empty :: WrappedArrow a b a0 # (<|>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 # some :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # many :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # | |
| Alternative m => Alternative (Kleisli m a) | Since: base-4.14.0.0 |
| (Generic1 f, Alternative (Rep1 f)) => Alternative (Generically1 f) | Since: base-4.17.0.0 |
Defined in GHC.Internal.Generics Methods empty :: Generically1 f a # (<|>) :: Generically1 f a -> Generically1 f a -> Generically1 f a # some :: Generically1 f a -> Generically1 f [a] # many :: Generically1 f a -> Generically1 f [a] # | |
| Alternative f => Alternative (Rec1 f) | Since: base-4.9.0.0 |
| (Alternative f, Alternative g) => Alternative (Product f g) | Since: base-4.9.0.0 |
| (Alternative f, Alternative g) => Alternative (f :*: g) | Since: base-4.9.0.0 |
| (Alternative f, Applicative g) => Alternative (Compose f g) | Since: base-4.9.0.0 |
| (Alternative f, Applicative g) => Alternative (f :.: g) | Since: base-4.9.0.0 |
| Alternative f => Alternative (M1 i c f) | Since: base-4.9.0.0 |
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*> with the types of the arguments reversed. It differs from
in that the effects are resolved in the order the arguments are
presented.flip (<*>)
Examples
>>>(<**>) (print 1) (id <$ print 2)1 2
>>>flip (<*>) (print 1) (id <$ print 2)2 1
>>>ZipList [4, 5, 6] <**> ZipList [(+1), (*2), (/3)]ZipList {getZipList = [5.0,10.0,2.0]}
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
optional :: Alternative f => f a -> f (Maybe a) #
One or none.
It is useful for modelling any computation that is allowed to fail.
Examples
Using the Alternative instance of Control.Monad.Except, the following functions:
>>>import Control.Monad.Except
>>>canFail = throwError "it failed" :: Except String Int>>>final = return 42 :: Except String Int
Can be combined by allowing the first function to fail:
>>>runExcept $ canFail *> finalLeft "it failed"
>>>runExcept $ optional canFail *> finalRight 42
The Const functor.
Examples
>>>fmap (++ "World") (Const "Hello")Const "Hello"
Because we ignore the second type parameter to Const,
the Applicative instance, which has
essentially turns into (<*>) :: Monoid m => Const m (a -> b) -> Const m a -> Const m bMonoid m => m -> m -> m, which is (<>)
>>>Const [1, 2, 3] <*> Const [4, 5, 6]Const [1,2,3,4,5,6]
Instances
| Generic1 (Const a :: k -> Type) | |||||
Defined in GHC.Internal.Data.Functor.Const Associated Types
| |||||
| Bifoldable (Const :: Type -> Type -> Type) | Since: base-4.10.0.0 | ||||
| Bifoldable1 (Const :: Type -> Type -> Type) | |||||
Defined in Data.Bifoldable1 | |||||
| Bifunctor (Const :: Type -> Type -> Type) | Since: base-4.8.0.0 | ||||
| Bitraversable (Const :: Type -> Type -> Type) | Since: base-4.10.0.0 | ||||
Defined in Data.Bitraversable Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Const a b -> f (Const c d) # | |||||
| Eq2 (Const :: Type -> Type -> Type) | Since: base-4.9.0.0 | ||||
| Ord2 (Const :: Type -> Type -> Type) | Since: base-4.9.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Read2 (Const :: Type -> Type -> Type) | 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 (Const a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Const a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Const a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Const a b] # | |||||
| Show2 (Const :: Type -> Type -> Type) | Since: base-4.9.0.0 | ||||
| Eq a => Eq1 (Const a :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Ord a => Ord1 (Const a :: Type -> Type) | Since: base-4.9.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Read a => Read1 (Const a :: Type -> Type) | Since: base-4.9.0.0 | ||||
Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Const a a0) # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Const a a0] # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Const a a0) # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Const a a0] # | |||||
| Show a => Show1 (Const a :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Contravariant (Const a :: Type -> Type) | |||||
| Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 | ||||
| Functor (Const m :: Type -> Type) | Since: base-2.1 | ||||
| Foldable (Const m :: Type -> Type) | Since: base-4.7.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods fold :: Monoid m0 => Const m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldr :: (a -> b -> b) -> b -> Const m a -> b # foldr' :: (a -> b -> b) -> b -> Const m a -> b # foldl :: (b -> a -> b) -> b -> Const m a -> b # foldl' :: (b -> a -> b) -> b -> Const m a -> b # foldr1 :: (a -> a -> a) -> Const m a -> a # foldl1 :: (a -> a -> a) -> Const m a -> a # elem :: Eq a => a -> Const m a -> Bool # maximum :: Ord a => Const m a -> a # minimum :: Ord a => Const m a -> a # | |||||
| Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0 | ||||
Defined in GHC.Internal.Data.Traversable | |||||
| Default a => Default (Const a b) | |||||
Defined in Data.Default.Internal | |||||
| Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 | ||||
| Semigroup a => Semigroup (Const a b) | Since: base-4.9.0.0 | ||||
| Bits a => Bits (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods (.&.) :: Const a b -> Const a b -> Const a b # (.|.) :: Const a b -> Const a b -> Const a b # xor :: Const a b -> Const a b -> Const a b # complement :: Const a b -> Const a b # shift :: Const a b -> Int -> Const a b # rotate :: Const a b -> Int -> Const a b # setBit :: Const a b -> Int -> Const a b # clearBit :: Const a b -> Int -> Const a b # complementBit :: Const a b -> Int -> Const a b # testBit :: Const a b -> Int -> Bool # bitSizeMaybe :: Const a b -> Maybe Int # isSigned :: Const a b -> Bool # shiftL :: Const a b -> Int -> Const a b # unsafeShiftL :: Const a b -> Int -> Const a b # shiftR :: Const a b -> Int -> Const a b # unsafeShiftR :: Const a b -> Int -> Const a b # rotateL :: Const a b -> Int -> Const a b # | |||||
| FiniteBits a => FiniteBits (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods finiteBitSize :: Const a b -> Int # countLeadingZeros :: Const a b -> Int # countTrailingZeros :: Const a b -> Int # | |||||
| IsString a => IsString (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.String Methods fromString :: String -> Const a b # | |||||
| Bounded a => Bounded (Const a b) | Since: base-4.9.0.0 | ||||
| Enum a => Enum (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods succ :: Const a b -> Const a b # pred :: Const a b -> Const a b # fromEnum :: Const a b -> Int # enumFrom :: Const a b -> [Const a b] # enumFromThen :: Const a b -> Const a b -> [Const a b] # enumFromTo :: Const a b -> Const a b -> [Const a b] # enumFromThenTo :: Const a b -> Const a b -> Const a b -> [Const a b] # | |||||
| Floating a => Floating (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods exp :: Const a b -> Const a b # log :: Const a b -> Const a b # sqrt :: Const a b -> Const a b # (**) :: Const a b -> Const a b -> Const a b # logBase :: Const a b -> Const a b -> Const a b # sin :: Const a b -> Const a b # cos :: Const a b -> Const a b # tan :: Const a b -> Const a b # asin :: Const a b -> Const a b # acos :: Const a b -> Const a b # atan :: Const a b -> Const a b # sinh :: Const a b -> Const a b # cosh :: Const a b -> Const a b # tanh :: Const a b -> Const a b # asinh :: Const a b -> Const a b # acosh :: Const a b -> Const a b # atanh :: Const a b -> Const a b # log1p :: Const a b -> Const a b # expm1 :: Const a b -> Const a b # | |||||
| RealFloat a => RealFloat (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods floatRadix :: Const a b -> Integer # floatDigits :: Const a b -> Int # floatRange :: Const a b -> (Int, Int) # decodeFloat :: Const a b -> (Integer, Int) # encodeFloat :: Integer -> Int -> Const a b # exponent :: Const a b -> Int # significand :: Const a b -> Const a b # scaleFloat :: Int -> Const a b -> Const a b # isInfinite :: Const a b -> Bool # isDenormalized :: Const a b -> Bool # isNegativeZero :: Const a b -> Bool # | |||||
| Storable a => Storable (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const | |||||
| Generic (Const a b) | |||||
Defined in GHC.Internal.Data.Functor.Const Associated Types
| |||||
| Ix a => Ix (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods range :: (Const a b, Const a b) -> [Const a b] # index :: (Const a b, Const a b) -> Const a b -> Int # unsafeIndex :: (Const a b, Const a b) -> Const a b -> Int # inRange :: (Const a b, Const a b) -> Const a b -> Bool # rangeSize :: (Const a b, Const a b) -> Int # unsafeRangeSize :: (Const a b, Const a b) -> Int # | |||||
| Num a => Num (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const | |||||
| Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 | ||||
| Fractional a => Fractional (Const a b) | Since: base-4.9.0.0 | ||||
| Integral a => Integral (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods quot :: Const a b -> Const a b -> Const a b # rem :: Const a b -> Const a b -> Const a b # div :: Const a b -> Const a b -> Const a b # mod :: Const a b -> Const a b -> Const a b # quotRem :: Const a b -> Const a b -> (Const a b, Const a b) # divMod :: Const a b -> Const a b -> (Const a b, Const a b) # | |||||
| Real a => Real (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const Methods toRational :: Const a b -> Rational # | |||||
| RealFrac a => RealFrac (Const a b) | Since: base-4.9.0.0 | ||||
| Show a => Show (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 | ||||
| Eq a => Eq (Const a b) | Since: base-4.9.0.0 | ||||
| Ord a => Ord (Const a b) | Since: base-4.9.0.0 | ||||
| type Rep1 (Const a :: k -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const | |||||
| type Rep (Const a b) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Functor.Const | |||||
Lists, but with an Applicative functor based on zipping.
Examples
In contrast to the Applicative for List:
>>>(+) <$> [1, 2, 3] <*> [4, 5, 6][5,6,7,6,7,8,7,8,9]
The Applicative instance of ZipList applies the operation
by pairing up the elements, analogous to zipWithN
>>>(+) <$> ZipList [1, 2, 3] <*> ZipList [4, 5, 6]ZipList {getZipList = [5,7,9]}
>>>(,,,) <$> ZipList [1, 2] <*> ZipList [3, 4] <*> ZipList [5, 6] <*> ZipList [7, 8]ZipList {getZipList = [(1,3,5,7),(2,4,6,8)]}
>>>ZipList [(+1), (^2), (/ 2)] <*> ZipList [5, 5, 5]ZipList {getZipList = [6.0,25.0,2.5]}
Constructors
| ZipList | |
Fields
| |
Instances
| Alternative ZipList | Since: base-4.11.0.0 | ||||
| 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 | ||||
| Functor ZipList | Since: base-2.1 | ||||
| Foldable ZipList | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Functor.ZipList Methods fold :: Monoid m => ZipList m -> m # foldMap :: Monoid m => (a -> m) -> ZipList a -> m # foldMap' :: Monoid m => (a -> m) -> ZipList a -> m # foldr :: (a -> b -> b) -> b -> ZipList a -> b # foldr' :: (a -> b -> b) -> b -> ZipList a -> b # foldl :: (b -> a -> b) -> b -> ZipList a -> b # foldl' :: (b -> a -> b) -> b -> ZipList a -> b # foldr1 :: (a -> a -> a) -> ZipList a -> a # foldl1 :: (a -> a -> a) -> ZipList a -> a # elem :: Eq a => a -> ZipList a -> Bool # maximum :: Ord a => ZipList a -> a # minimum :: Ord a => ZipList a -> a # | |||||
| Traversable ZipList | Since: base-4.9.0.0 | ||||
| Generic1 ZipList | |||||
Defined in GHC.Internal.Functor.ZipList Associated Types
| |||||
| Data a => Data (ZipList a) | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Functor.ZipList Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ZipList a -> c (ZipList a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ZipList a) # toConstr :: ZipList a -> Constr # dataTypeOf :: ZipList a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (ZipList a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ZipList a)) # gmapT :: (forall b. Data b => b -> b) -> ZipList a -> ZipList a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ZipList a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ZipList a -> r # gmapQ :: (forall d. Data d => d -> u) -> ZipList a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ZipList a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ZipList a -> m (ZipList a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ZipList a -> m (ZipList a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ZipList a -> m (ZipList a) # | |||||
| Generic (ZipList a) | |||||
Defined in GHC.Internal.Functor.ZipList Associated Types
| |||||
| IsList (ZipList a) | Since: base-4.15.0.0 | ||||
| Read a => Read (ZipList a) | Since: base-4.7.0.0 | ||||
| Show a => Show (ZipList a) | Since: base-4.7.0.0 | ||||
| Eq a => Eq (ZipList a) | Since: base-4.7.0.0 | ||||
| Ord a => Ord (ZipList a) | Since: base-4.7.0.0 | ||||
| type Rep1 ZipList | Since: base-4.7.0.0 | ||||
Defined in GHC.Internal.Functor.ZipList | |||||
| type Rep (ZipList a) | Since: base-4.7.0.0 | ||||
Defined in GHC.Internal.Functor.ZipList | |||||
| type Item (ZipList a) | |||||
Defined in GHC.Internal.IsList | |||||
(&&&) :: Arrow a => a b c -> a b c' -> a b (c, c') infixr 3 #
Fanout: send the input to both argument arrows and combine their output.
The default definition may be overridden with a more efficient version if desired.
(>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c infixr 1 #
Left-to-right composition
(<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c infixr 1 #
Right-to-left composition
module Control.Concurrent.MVar
data SomeException #
The SomeException type is the root of the exception type hierarchy.
When an exception of type e is thrown, behind the scenes it is
encapsulated in a SomeException.
Constructors
| (Exception e, HasExceptionContext) => SomeException e |
Instances
| Exception SomeException | This drops any attached Since: base-3.0 |
Defined in GHC.Internal.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # backtraceDesired :: SomeException -> Bool # | |
| Show SomeException | Since: ghc-internal-3.0 |
Defined in GHC.Internal.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # | |
class (Typeable e, Show e) => Exception e #
Any type that you wish to throw or catch as an exception must be an
instance of the Exception class. The simplest case is a new exception
type directly below the root:
data MyException = ThisException | ThatException
deriving Show
instance Exception MyExceptionThe default method definitions in the Exception class do what we need
in this case. You can now throw and catch ThisException and
ThatException as exceptions:
*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
Caught ThisException
In more complicated examples, you may wish to define a whole hierarchy of exceptions:
---------------------------------------------------------------------
-- Make the root exception type for all the exceptions in a compiler
data SomeCompilerException = forall e . Exception e => SomeCompilerException e
instance Show SomeCompilerException where
show (SomeCompilerException e) = show e
instance Exception SomeCompilerException
compilerExceptionToException :: Exception e => e -> SomeException
compilerExceptionToException = toException . SomeCompilerException
compilerExceptionFromException :: Exception e => SomeException -> Maybe e
compilerExceptionFromException x = do
SomeCompilerException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make a subhierarchy for exceptions in the frontend of the compiler
data SomeFrontendException = forall e . Exception e => SomeFrontendException e
instance Show SomeFrontendException where
show (SomeFrontendException e) = show e
instance Exception SomeFrontendException where
toException = compilerExceptionToException
fromException = compilerExceptionFromException
frontendExceptionToException :: Exception e => e -> SomeException
frontendExceptionToException = toException . SomeFrontendException
frontendExceptionFromException :: Exception e => SomeException -> Maybe e
frontendExceptionFromException x = do
SomeFrontendException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make an exception type for a particular frontend compiler exception
data MismatchedParentheses = MismatchedParentheses
deriving Show
instance Exception MismatchedParentheses where
toException = frontendExceptionToException
fromException = frontendExceptionFromExceptionWe can now catch a MismatchedParentheses exception as
MismatchedParentheses, SomeFrontendException or
SomeCompilerException, but not other types, e.g. IOException:
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException))
*** Exception: MismatchedParentheses
Instances
class Applicative m => Monad (m :: Type -> Type) where #
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:
- Left identity
returna>>=k = k a- Right identity
m>>=return= m- Associativity
m>>=(\x -> k x>>=h) = (m>>=k)>>=h
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 List, Maybe and IO
defined in the Prelude satisfy these laws.
Minimal complete definition
Methods
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
'as ' can be understood as the >>= bsdo expression
do a <- as bs a
An alternative name for this function is 'bind', but some people may refer to it as 'flatMap', which results from it being equivialent to
\x f ->join(fmapf x) :: Monad m => m a -> (a -> m b) -> m b
which can be seen as mapping a value with
Monad m => m a -> m (m b) and then 'flattening' m (m b) to m b using join.
Instances
| Monad Complex | Since: base-4.9.0.0 |
| Monad First | Since: base-4.9.0.0 |
| Monad Last | Since: base-4.9.0.0 |
| Monad Max | Since: base-4.9.0.0 |
| Monad Min | Since: base-4.9.0.0 |
| Monad Put | |
| Monad Seq | |
| Monad Tree | |
| Monad NonEmpty | Since: base-4.9.0.0 |
| Monad Identity | Since: base-4.8.0.0 |
| Monad Down | Since: base-4.11.0.0 |
| Monad Par1 | Since: base-4.9.0.0 |
| Monad P | Since: base-2.1 |
| Monad ReadP | Since: base-2.1 |
| Monad IO | Since: base-2.1 |
| Monad Maybe | Since: base-2.1 |
| Monad Solo | Since: base-4.15 |
| Monad [] | Since: base-2.1 |
| Monad m => Monad (WrappedMonad m) | Since: base-4.7.0.0 |
Defined in Control.Applicative Methods (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # return :: a -> WrappedMonad m a # | |
| Monad (SetM s) | |
| ArrowApply a => Monad (ArrowMonad a) | Since: base-2.1 |
Defined in GHC.Internal.Control.Arrow Methods (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # return :: a0 -> ArrowMonad a a0 # | |
| Monad (Either e) | Since: base-4.4.0.0 |
| Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Monad (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Monad (IParser t) | |
| Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
| (Applicative f, Monad f) => Monad (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods (>>=) :: WhenMissing f x a -> (a -> WhenMissing f x b) -> WhenMissing f x b # (>>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # return :: a -> WhenMissing f x a # | |
| Monad m => Monad (Kleisli m a) | Since: base-4.14.0.0 |
| Monad f => Monad (Rec1 f) | Since: base-4.9.0.0 |
| (Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0 |
| (Monad f, Monad g) => Monad (Product f g) | Since: base-4.9.0.0 |
| (Monad f, Applicative f) => Monad (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods (>>=) :: WhenMatched f x y a -> (a -> WhenMatched f x y b) -> WhenMatched f x y b # (>>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # return :: a -> WhenMatched f x y a # | |
| (Applicative f, Monad f) => Monad (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods (>>=) :: WhenMissing f k x a -> (a -> WhenMissing f k x b) -> WhenMissing f k x b # (>>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # return :: a -> WhenMissing f k x a # | |
| (Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0 |
| (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
| Monad ((->) r) | Since: base-2.1 |
| (Monad f, Applicative f) => Monad (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods (>>=) :: WhenMatched f k x y a -> (a -> WhenMatched f k x y b) -> WhenMatched f k x y b # (>>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # return :: a -> WhenMatched f k x y a # | |
| Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
guard :: Alternative f => Bool -> f () #
Conditional failure of Alternative computations. Defined by
guard True =pure() guard False =empty
Examples
Common uses of guard include conditionally signalling an error in
an error monad and conditionally rejecting the current choice in an
Alternative-based parser.
As an example of signalling an error in the error monad Maybe,
consider a safe division function safeDiv x y that returns
Nothing when the denominator y is zero and otherwise. For example:Just (x `div`
y)
>>>safeDiv 4 0Nothing
>>>safeDiv 4 2Just 2
A definition of safeDiv using guards, but not guard:
safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0 = Just (x `div` y)
| otherwise = Nothing
A definition of safeDiv using guard and Monad do-notation:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
join :: Monad m => m (m a) -> m a #
The join function is the conventional monad join operator. It
is used to remove one level of monadic structure, projecting its
bound argument into the outer level.
'' can be understood as the join bssdo expression
do bs <- bss bs
Examples
>>>join [[1, 2, 3], [4, 5, 6], [7, 8, 9]][1,2,3,4,5,6,7,8,9]
>>>join (Just (Just 3))Just 3
A common use of join is to run an IO computation returned from
an STM transaction, since STM transactions
can't perform IO directly. Recall that
atomically :: STM a -> IO a
is used to run STM transactions atomically. So, by
specializing the types of atomically and join to
atomically:: STM (IO b) -> IO (IO b)join:: IO (IO b) -> IO b
we can compose them as
join.atomically:: STM (IO b) -> IO b
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Minimal complete definition
Nothing
Methods
The identity of mplus. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>)
Instances
| MonadPlus Seq | |
| MonadPlus P | Since: base-2.1 |
Defined in GHC.Internal.Text.ParserCombinators.ReadP | |
| MonadPlus ReadP | Since: base-2.1 |
| MonadPlus IO | Takes the first non-throwing Since: base-4.9.0.0 |
| MonadPlus Maybe | Picks the leftmost Since: base-2.1 |
| MonadPlus [] | Combines lists by concatenation, starting from the empty list. Since: base-2.1 |
Defined in GHC.Internal.Base | |
| (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in GHC.Internal.Control.Arrow | |
| MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus m => MonadPlus (Kleisli m a) | Since: base-4.14.0.0 |
| MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (Product f g) | Since: base-4.9.0.0 |
| (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0 |
| MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0 |
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=, but with the arguments interchanged.
as >>= f == f =<< as
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative expressions. For example,
Examples
when debug (putStrLn "Debugging")
will output the string Debugging if the Boolean value debug
is True, and otherwise do nothing.
>>>putStr "pi:" >> when False (print 3.14159)pi:
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter function.
runIdentity (filterM (Identity . p) xs) == filter p xs
Examples
>>>filterM (\x -> doputStrLn ("Keep: " ++ show x ++ "?") answer <- getLine pure (answer == "y")) [1, 2, 3] Keep: 1? y Keep: 2? n Keep: 3? y [1,3]
>>>filterM (\x -> doputStr (show x) x' <- readLn pure (x == x')) [1, 2, 3] 12 22 33 [2,3]
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Examples
A common use of forever is to process input from network sockets,
Handles, and channels
(e.g. MVar and
Chan).
For example, here is how we might implement an echo
server, using
forever both to listen for client connections on a network socket
and to echo client input on client connection handles:
echoServer :: Socket -> IO () echoServer socket =forever$ do client <- accept socketforkFinally(echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client =forever$ hGetLine client >>= hPutStrLn client
Note that "forever" isn't necessarily non-terminating.
If the action is in a and short-circuits after some number of iterations.
then MonadPlus actually returns forevermzero, effectively short-circuiting its caller.
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
replicateM :: Applicative m => Int -> m a -> m [a] #
performs the action replicateM n actact n times,
and then returns the list of results.
replicateM n (pure x) == replicate n xExamples
>>>replicateM 3 getLinehi heya hiya ["hi","heya","hiya"]
>>>import Control.Monad.State>>>runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1([1,2,3],4)
replicateM_ :: Applicative m => Int -> m a -> m () #
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when.
Examples
>>>do x <- getLineunless (x == "hi") (putStrLn "hi!") comingupwithexamplesisdifficult hi!
>>>unless (pi > exp 1) NothingJust ()
module Control.Monad.Fail
module Control.Monad.IO.Class
module Data.Bifunctor
toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b #
Attempt to convert an Integral type a to an Integral type b using
the size of the types as measured by Bits methods.
A simpler version of this function is:
toIntegral :: (Integral a, Integral b) => a -> Maybe b
toIntegral x
| toInteger x == toInteger y = Just y
| otherwise = Nothing
where
y = fromIntegral xThis version requires going through Integer, which can be inefficient.
However, toIntegralSized is optimized to allow GHC to statically determine
the relative type sizes (as measured by bitSizeMaybe and isSigned) and
avoid going through Integer for many types. (The implementation uses
fromIntegral, which is itself optimized with rules for base types but may
go through Integer for some type pairs.)
Since: base-4.8.0.0
module Data.Bool
The character type Char represents Unicode codespace
and its elements are code points as in definitions
D9 and D10 of the Unicode Standard.
Character literals in Haskell are single-quoted: 'Q', 'Я' or 'Ω'.
To represent a single quote itself use '\'', and to represent a backslash
use '\\'. The full grammar can be found in the section 2.6 of the
Haskell 2010 Language Report.
To specify a character by its code point one can use decimal, hexadecimal
or octal notation: '\65', '\x41' and '\o101' are all alternative forms
of 'A'. The largest code point is '\x10ffff'.
There is a special escape syntax for ASCII control characters:
| Escape | Alternatives | Meaning |
|---|---|---|
'\NUL' | '\0' | null character |
'\SOH' | '\1' | start of heading |
'\STX' | '\2' | start of text |
'\ETX' | '\3' | end of text |
'\EOT' | '\4' | end of transmission |
'\ENQ' | '\5' | enquiry |
'\ACK' | '\6' | acknowledge |
'\BEL' | '\7', '\a' | bell (alert) |
'\BS' | '\8', '\b' | backspace |
'\HT' | '\9', '\t' | horizontal tab |
'\LF' | '\10', '\n' | line feed (new line) |
'\VT' | '\11', '\v' | vertical tab |
'\FF' | '\12', '\f' | form feed |
'\CR' | '\13', '\r' | carriage return |
'\SO' | '\14' | shift out |
'\SI' | '\15' | shift in |
'\DLE' | '\16' | data link escape |
'\DC1' | '\17' | device control 1 |
'\DC2' | '\18' | device control 2 |
'\DC3' | '\19' | device control 3 |
'\DC4' | '\20' | device control 4 |
'\NAK' | '\21' | negative acknowledge |
'\SYN' | '\22' | synchronous idle |
'\ETB' | '\23' | end of transmission block |
'\CAN' | '\24' | cancel |
'\EM' | '\25' | end of medium |
'\SUB' | '\26' | substitute |
'\ESC' | '\27' | escape |
'\FS' | '\28' | file separator |
'\GS' | '\29' | group separator |
'\RS' | '\30' | record separator |
'\US' | '\31' | unit separator |
'\SP' | '\32', ' ' | space |
'\DEL' | '\127' | delete |
Instances
module Data.Coerce
module Data.Either
module Data.Eq
const x y always evaluates to x, ignoring its second argument.
const x = \_ -> x
This function might seem useless at first glance, but it can be very useful in a higher order context.
Examples
>>>const 42 "hello"42
>>>map (const 42) [0..3][42,42,42,42]
($) :: (a -> b) -> a -> b infixr 0 #
is the function application operator.($)
Applying to a function ($)f and an argument x gives the same result as applying f to x directly. The definition is akin to this:
($) :: (a -> b) -> a -> b ($) f x = f x
This is specialized from ida -> a to (a -> b) -> (a -> b) which by the associativity of (->)
is the same as (a -> b) -> a -> b.
On the face of it, this may appear pointless! But it's actually one of the most useful and important operators in Haskell.
The order of operations is very different between ($) and normal function application. Normal function application has precedence 10 - higher than any operator - and associates to the left. So these two definitions are equivalent:
expr = min 5 1 + 5 expr = ((min 5) 1) + 5
($) has precedence 0 (the lowest) and associates to the right, so these are equivalent:
expr = min 5 $ 1 + 5 expr = (min 5) (1 + 5)
Examples
A common use cases of ($) is to avoid parentheses in complex expressions.
For example, instead of using nested parentheses in the following Haskell function:
-- | Sum numbers in a string: strSum "100 5 -7" == 98 strSum ::String->IntstrSum s =sum(mapMaybereadMaybe(wordss))
we can deploy the function application operator:
-- | Sum numbers in a string: strSum "100 5 -7" == 98 strSum ::String->IntstrSum s =sum$mapMaybereadMaybe$wordss
($) is also used as a section (a partially applied operator), in order to indicate that we wish to apply some yet-unspecified function to a given value. For example, to apply the argument 5 to a list of functions:
applyFive :: [Int] applyFive = map ($ 5) [(+1), (2^)] >>> [6, 32]
Technical Remark (Representation Polymorphism)
($) is fully representation-polymorphic. This allows it to also be used with arguments of unlifted and even unboxed kinds, such as unboxed integers:
fastMod :: Int -> Int -> Int fastMod (I# x) (I# m) = I# $ remInt# x m
Identity function.
id x = x
This function might seem useless at first glance, but it can be very useful in a higher order context.
Examples
>>>length $ filter id [True, True, False, True]3
>>>Just (Just 3) >>= idJust 3
>>>foldr id 0 [(^3), (*5), (+2)]1000
(.) :: (b -> c) -> (a -> b) -> a -> c infixr 9 #
Right to left function composition.
(f . g) x = f (g x)
f . id = f = id . f
Examples
>>>map ((*2) . length) [[], [0, 1, 2], [0]][0,6,2]
>>>foldr (.) id [(+1), (*3), (^3)] 225
>>>let (...) = (.).(.) in ((*2)...(+)) 5 1030
flip :: (a -> b -> c) -> b -> a -> c #
takes its (first) two arguments in the reverse order of flip ff.
flip f x y = f y x
flip . flip = id
Examples
>>>flip (++) "hello" "world""worldhello"
>>>let (.>) = flip (.) in (+1) .> show $ 5"6"
is the least fixed point of the function fix ff,
i.e. the least defined x such that f x = x.
When f is strict, this means that because, by the definition of strictness,
f ⊥ = ⊥ and such the least defined fixed point of any strict function is ⊥.
Examples
We can write the factorial function using direct recursion as
>>>let fac n = if n <= 1 then 1 else n * fac (n-1) in fac 5120
This uses the fact that Haskell’s let introduces recursive bindings. We can
rewrite this definition using fix,
Instead of making a recursive call, we introduce a dummy parameter rec;
when used within fix, this parameter then refers to fix’s argument, hence
the recursion is reintroduced.
>>>fix (\rec n -> if n <= 1 then 1 else n * rec (n-1)) 5120
Using fix, we can implement versions of repeat as
and fix . (:)cycle as fix . (++)
>>>take 10 $ fix (0:)[0,0,0,0,0,0,0,0,0,0]
>>>map (fix (\rec n -> if n < 2 then n else rec (n - 1) + rec (n - 2))) [1..10][1,1,2,3,5,8,13,21,34,55]
Implementation Details
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c infixl 0 #
runs the binary function on b u x yb on the results of applying
unary function u to two arguments x and y. From the opposite
perspective, it transforms two inputs and combines the outputs.
(op `on` f) x y = f x `op` f y
Examples
>>>sortBy (compare `on` length) [[0, 1, 2], [0, 1], [], [0]][[],[0],[0,1],[0,1,2]]
>>>((+) `on` length) [1, 2, 3] [-1]4
>>>((,) `on` (*2)) 2 3(4,6)
Algebraic properties
(&) :: a -> (a -> b) -> b infixl 1 #
& is a reverse application operator. This provides notational
convenience. Its precedence is one higher than that of the forward
application operator $, which allows & to be nested in $.
This is a version of , where flip idid is specialized from a -> a to (a -> b) -> (a -> b)
which by the associativity of (->) is (a -> b) -> a -> b.
flipping this yields a -> (a -> b) -> b which is the type signature of &
Examples
>>>5 & (+1) & show"6"
>>>sqrt $ [1 / n^2 | n <- [1..1000]] & sum & (*6)3.1406380562059946
Since: base-4.8.0.0
class Functor (f :: Type -> Type) where #
A type f is a Functor if it provides a function fmap which, given any types a and b
lets you apply any function from (a -> b) to turn an f a into an f b, preserving the
structure of f. Furthermore f needs to adhere to the following:
Note, that the second law follows from the free theorem of the type fmap and
the first law, so you need only check that the former condition holds.
See these articles by School of Haskell or
David Luposchainsky
for an explanation.
Minimal complete definition
Methods
fmap :: (a -> b) -> f a -> f b #
fmap is used to apply a function of type (a -> b) to a value of type f a,
where f is a functor, to produce a value of type f b.
Note that for any type constructor with more than one parameter (e.g., Either),
only the last type parameter can be modified with fmap (e.g., b in `Either a b`).
Some type constructors with two parameters or more have a instance that allows
both the last and the penultimate parameters to be mapped over.Bifunctor
Examples
Convert from a to a Maybe IntMaybe String
using show:
>>>fmap show NothingNothing>>>fmap show (Just 3)Just "3"
Convert from an to an
Either Int IntEither Int String using show:
>>>fmap show (Left 17)Left 17>>>fmap show (Right 17)Right "17"
Double each element of a list:
>>>fmap (*2) [1,2,3][2,4,6]
Apply even to the second element of a pair:
>>>fmap even (2,2)(2,True)
It may seem surprising that the function is only applied to the last element of the tuple
compared to the list example above which applies it to every element in the list.
To understand, remember that tuples are type constructors with multiple type parameters:
a tuple of 3 elements (a,b,c) can also be written (,,) a b c and its Functor instance
is defined for Functor ((,,) a b) (i.e., only the third parameter is free to be mapped over
with fmap).
It explains why fmap can be used with tuples containing values of different types as in the
following example:
>>>fmap even ("hello", 1.0, 4)("hello",1.0,True)
Instances
| Functor Complex | Since: base-4.9.0.0 |
| Functor First | Since: base-4.9.0.0 |
| Functor Last | Since: base-4.9.0.0 |
| Functor Max | Since: base-4.9.0.0 |
| Functor Min | Since: base-4.9.0.0 |
| Functor ArgDescr | Since: base-4.7.0.0 |
| Functor ArgOrder | Since: base-4.7.0.0 |
| Functor OptDescr | Since: base-4.7.0.0 |
| Functor Put | |
| Functor SCC | Since: containers-0.5.4 |
| Functor IntMap | |
| Functor Digit | |
| Functor Elem | |
| Functor FingerTree | |
Defined in Data.Sequence.Internal Methods fmap :: (a -> b) -> FingerTree a -> FingerTree b # (<$) :: a -> FingerTree b -> FingerTree a # | |
| Functor Node | |
| Functor Seq | |
| Functor ViewL | |
| Functor ViewR | |
| Functor Tree | |
| Functor NonEmpty | Since: base-4.9.0.0 |
| Functor Identity | Since: base-4.8.0.0 |
| Functor Down | Since: base-4.11.0.0 |
| Functor ZipList | Since: base-2.1 |
| Functor Par1 | Since: base-4.9.0.0 |
| Functor P | Since: base-4.8.0.0 |
Defined in GHC.Internal.Text.ParserCombinators.ReadP | |
| Functor ReadP | Since: base-2.1 |
| Functor IO | Since: base-2.1 |
| Functor Maybe | Since: base-2.1 |
| Functor Solo | Since: base-4.15 |
| Functor [] | Since: base-2.1 |
Defined in GHC.Internal.Base | |
| Monad m => Functor (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative Methods fmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b # (<$) :: a -> WrappedMonad m b -> WrappedMonad m a # | |
| Functor (Arg a) | Since: base-4.9.0.0 |
| Functor (SetM s) | |
Defined in Data.Graph | |
| Functor (Map k) | |
| Arrow a => Functor (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in GHC.Internal.Control.Arrow Methods fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # (<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
| Functor (Either a) | Since: base-3.0 |
| Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Functor (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (V1 :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (IParser t) | |
| Functor ((,) a) | Since: base-2.1 |
Defined in GHC.Internal.Base | |
| 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 # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
| (Applicative f, Monad f) => Functor (WhenMissing f x) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods fmap :: (a -> b) -> WhenMissing f x a -> WhenMissing f x b # (<$) :: a -> WhenMissing f x b -> WhenMissing f x a # | |
| Functor m => Functor (Kleisli m a) | Since: base-4.14.0.0 |
| Functor (Const m :: Type -> Type) | Since: base-2.1 |
| (Generic1 f, Functor (Rep1 f)) => Functor (Generically1 f) | Since: base-4.17.0.0 |
Defined in GHC.Internal.Generics Methods fmap :: (a -> b) -> Generically1 f a -> Generically1 f b # (<$) :: a -> Generically1 f b -> Generically1 f a # | |
| Functor f => Functor (Rec1 f) | Since: base-4.9.0.0 |
| Functor (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Char :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Double :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Float :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Int :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Word :: Type -> Type) | Since: base-4.9.0.0 |
| Functor ((,,) a b) | Since: base-4.14.0.0 |
Defined in GHC.Internal.Base | |
| (Functor f, Functor g) => Functor (Product f g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (Sum f g) | Since: base-4.9.0.0 |
| Functor f => Functor (WhenMatched f x y) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods fmap :: (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b # (<$) :: a -> WhenMatched f x y b -> WhenMatched f x y a # | |
| (Applicative f, Monad f) => Functor (WhenMissing f k x) | Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods fmap :: (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b # (<$) :: a -> WhenMissing f k x b -> WhenMissing f k x a # | |
| (Functor f, Functor g) => Functor (f :*: g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :+: g) | Since: base-4.9.0.0 |
| Functor (K1 i c :: Type -> Type) | Since: base-4.9.0.0 |
| Functor ((,,,) a b c) | Since: base-4.14.0.0 |
Defined in GHC.Internal.Base | |
| Functor ((->) r) | Since: base-2.1 |
Defined in GHC.Internal.Base | |
| (Functor f, Functor g) => Functor (Compose f g) | Since: base-4.9.0.0 |
| Functor f => Functor (WhenMatched f k x y) | Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods fmap :: (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b # (<$) :: a -> WhenMatched f k x y b -> WhenMatched f k x y a # | |
| (Functor f, Functor g) => Functor (f :.: g) | Since: base-4.9.0.0 |
| Functor f => Functor (M1 i c f) | Since: base-4.9.0.0 |
| Functor ((,,,,) a b c d) | Since: base-4.18.0.0 |
Defined in GHC.Internal.Base | |
| Functor ((,,,,,) a b c d e) | Since: base-4.18.0.0 |
Defined in GHC.Internal.Base | |
| Functor ((,,,,,,) a b c d e f) | Since: base-4.18.0.0 |
Defined in GHC.Internal.Base | |
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
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)
($>) :: Functor f => f a -> b -> f b infixl 4 #
Flipped version of <$.
Examples
Replace the contents of a with a constant
Maybe IntString:
>>>Nothing $> "foo"Nothing
>>>Just 90210 $> "foo"Just "foo"
Replace the contents of an
with a constant Either Int IntString, resulting in an :Either
Int String
>>>Left 8675309 $> "foo"Left 8675309
>>>Right 8675309 $> "foo"Right "foo"
Replace each element of a list with a constant String:
>>>[1,2,3] $> "foo"["foo","foo","foo"]
Replace the second element of a pair with a constant String:
>>>(1,2) $> "foo"(1,"foo")
Since: base-4.7.0.0
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing
>>>void (Just 3)Just ()
Replace the contents of an
with unit, resulting in an Either Int Int:Either Int ()
>>>void (Left 8675309)Left 8675309
>>>void (Right 8675309)Right ()
Replace every element of a list with unit:
>>>void [1,2,3][(),(),()]
Replace the second element of a pair with unit:
>>>void (1,2)(1,())
Discard the result of an IO action:
>>>mapM print [1,2]1 2 [(),()]
>>>void $ mapM print [1,2]1 2
module Data.Functor.Compose
class Contravariant (f :: Type -> Type) where #
The class of contravariant functors.
Whereas in Haskell, one can think of a Functor as containing or producing
values, a contravariant functor is a functor that can be thought of as
consuming values.
As an example, consider the type of predicate functions a -> Bool. One
such predicate might be negative x = x < 0, which
classifies integers as to whether they are negative. However, given this
predicate, we can re-use it in other situations, providing we have a way to
map values to integers. For instance, we can use the negative predicate
on a person's bank balance to work out if they are currently overdrawn:
newtype Predicate a = Predicate { getPredicate :: a -> Bool }
instance Contravariant Predicate where
contramap :: (a' -> a) -> (Predicate a -> Predicate a')
contramap f (Predicate p) = Predicate (p . f)
| `- First, map the input...
`----- then apply the predicate.
overdrawn :: Predicate Person
overdrawn = contramap personBankBalance negative
Any instance should be subject to the following laws:
Note, that the second law follows from the free theorem of the type of
contramap and the first law, so you need only check that the former
condition holds.
Minimal complete definition
Instances
| Contravariant Comparison | A |
Defined in Data.Functor.Contravariant Methods contramap :: (a' -> a) -> Comparison a -> Comparison a' # (>$) :: b -> Comparison b -> Comparison a # | |
| Contravariant Equivalence | Equivalence relations are |
Defined in Data.Functor.Contravariant Methods contramap :: (a' -> a) -> Equivalence a -> Equivalence a' # (>$) :: b -> Equivalence b -> Equivalence a # | |
| Contravariant Predicate | A Without newtypes contramap :: (a' -> a) -> (Predicate a -> Predicate a') contramap f (Predicate g) = Predicate (g . f) |
| Contravariant (Op a) | |
| Contravariant (Proxy :: Type -> Type) | |
| Contravariant (U1 :: Type -> Type) | |
| Contravariant (V1 :: Type -> Type) | |
| Contravariant (Const a :: Type -> Type) | |
| Contravariant f => Contravariant (Alt f) | |
| Contravariant f => Contravariant (Rec1 f) | |
| (Contravariant f, Contravariant g) => Contravariant (Product f g) | |
| (Contravariant f, Contravariant g) => Contravariant (Sum f g) | |
| (Contravariant f, Contravariant g) => Contravariant (f :*: g) | |
| (Contravariant f, Contravariant g) => Contravariant (f :+: g) | |
| Contravariant (K1 i c :: Type -> Type) | |
| (Functor f, Contravariant g) => Contravariant (Compose f g) | |
| (Functor f, Contravariant g) => Contravariant (f :.: g) | |
| Contravariant f => Contravariant (M1 i c f) | |
(>$<) :: Contravariant f => (a -> b) -> f b -> f a infixl 4 #
This is an infix alias for contramap.
module Data.Functor.Identity
module Data.Int
type Constraint = CONSTRAINT LiftedRep #
The kind of lifted constraints
unfoldr :: (b -> Maybe (a, b)) -> b -> [a] #
The unfoldr function is a `dual' to foldr: while foldr
reduces a list to a summary value, unfoldr builds a list from
a seed value. The function takes the element and returns Nothing
if it is done producing the list or returns Just (a,b), in which
case, a is a prepended to the list and b is used as the next
element in a recursive call. For example,
iterate f == unfoldr (\x -> Just (x, f x))
In some cases, unfoldr can undo a foldr operation:
unfoldr f' (foldr f z xs) == xs
if the following holds:
f' (f x y) = Just (x,y) f' z = Nothing
Laziness
>>>take 1 (unfoldr (\x -> Just (x, undefined)) 'a')"a"
Examples
>>>unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10[10,9,8,7,6,5,4,3,2,1]
>>>take 10 $ unfoldr (\(x, y) -> Just (x, (y, x + y))) (0, 1)[0,1,1,2,3,5,8,13,21,54]
sortOn :: Ord b => (a -> b) -> [a] -> [a] #
Sort a list by comparing the results of a key function applied to each
element. is equivalent to sortOn f, but has the
performance advantage of only evaluating sortBy (comparing f)f once for each element in the
input list. This is called the decorate-sort-undecorate paradigm, or
Schwartzian transform.
Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input.
The argument must be finite.
Examples
>>>sortOn fst [(2, "world"), (4, "!"), (1, "Hello")][(1,"Hello"),(2,"world"),(4,"!")]
>>>sortOn length ["jim", "creed", "pam", "michael", "dwight", "kevin"]["jim","pam","creed","kevin","dwight","michael"]
Performance notes
This function minimises the projections performed, by materialising the projections in an intermediate list.
For trivial projections, you should prefer using sortBy with
comparing, for example:
>>>sortBy (comparing fst) [(3, 1), (2, 2), (1, 3)][(1,3),(2,2),(3,1)]
Or, for the exact same API as sortOn, you can use `sortBy . comparing`:
>>>(sortBy . comparing) fst [(3, 1), (2, 2), (1, 3)][(1,3),(2,2),(3,1)]
Since: base-4.8.0.0
The transpose function transposes the rows and columns of its argument.
Laziness
transpose is lazy in its elements
>>>take 1 (transpose ['a' : undefined, 'b' : undefined])["ab"]
Examples
>>>transpose [[1,2,3],[4,5,6]][[1,4],[2,5],[3,6]]
If some of the rows are shorter than the following rows, their elements are skipped:
>>>transpose [[10,11],[20],[],[30,31,32]][[10,20,30],[11,31],[32]]
For this reason the outer list must be finite; otherwise transpose hangs:
>>>transpose (repeat [])* Hangs forever *
sortBy :: (a -> a -> Ordering) -> [a] -> [a] #
The sortBy function is the non-overloaded version of sort.
The argument must be finite.
The supplied comparison relation is supposed to be reflexive and antisymmetric,
otherwise, e. g., for _ _ -> GT, the ordered list simply does not exist.
The relation is also expected to be transitive: if it is not then sortBy
might fail to find an ordered permutation, even if it exists.
Examples
>>>sortBy (\(a,_) (b,_) -> compare a b) [(2, "world"), (4, "!"), (1, "Hello")][(1,"Hello"),(2,"world"),(4,"!")]
(++) :: [a] -> [a] -> [a] infixr 5 #
(++) appends 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.
Performance considerations
This function takes linear time in the number of elements of the
first list. Thus it is better to associate repeated
applications of (++) to the right (which is the default behaviour):
xs ++ (ys ++ zs) or simply xs ++ ys ++ zs, but not (xs ++ ys) ++ zs.
For the same reason concat = foldr (++) []
has linear performance, while foldl (++) [] is prone
to quadratic slowdown
Examples
>>>[1, 2, 3] ++ [4, 5, 6][1,2,3,4,5,6]
>>>[] ++ [1, 2, 3][1,2,3]
>>>[3, 2, 1] ++ [][3,2,1]
filter :: (a -> Bool) -> [a] -> [a] #
\(\mathcal{O}(n)\). 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]
Examples
>>>filter odd [1, 2, 3][1,3]
>>>filter (\l -> length l > 3) ["Hello", ", ", "World", "!"]["Hello","World"]
>>>filter (/= 3) [1, 2, 3, 4, 3, 2, 1][1,2,4,2,1]
zip :: [a] -> [b] -> [(a, b)] #
\(\mathcal{O}(\min(m,n))\). zip takes two lists and returns a list of
corresponding pairs.
zip is right-lazy:
>>>zip [] undefined[]>>>zip undefined []*** Exception: Prelude.undefined ...
zip is capable of list fusion, but it is restricted to its
first list argument and its resulting list.
Examples
>>>zip [1, 2, 3] ['a', 'b', 'c'][(1,'a'),(2,'b'),(3,'c')]
If one input list is shorter than the other, excess elements of the longer list are discarded, even if one of the lists is infinite:
>>>zip [1] ['a', 'b'][(1,'a')]
>>>zip [1, 2] ['a'][(1,'a')]
>>>zip [] [1..][]
>>>zip [1..] [][]
map :: (a -> b) -> [a] -> [b] #
\(\mathcal{O}(n)\). 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, ...]
this means that map id == id
Examples
>>>map (+1) [1, 2, 3][2,3,4]
>>>map id [1, 2, 3][1,2,3]
>>>map (\n -> 3 * n + 1) [1, 2, 3][4,7,10]
uncons :: [a] -> Maybe (a, [a]) #
\(\mathcal{O}(1)\). Decompose a list into its head and tail.
- If the list is empty, returns
Nothing. - If the list is non-empty, returns
, whereJust(x, xs)xis theheadof the list andxsitstail.
Examples
>>>uncons []Nothing
>>>uncons [1]Just (1,[])
>>>uncons [1, 2, 3]Just (1,[2,3])
Since: base-4.8.0.0
scanl :: (b -> a -> b) -> b -> [a] -> [b] #
\(\mathcal{O}(n)\). scanl is similar to foldl, but returns a list of
successive reduced values from the left:
scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...]
Note that
last (scanl f z xs) == foldl f z xs
Examples
>>>scanl (+) 0 [1..4][0,1,3,6,10]
>>>scanl (+) 42 [][42]
>>>scanl (-) 100 [1..4][100,99,97,94,90]
>>>scanl (\reversedString nextChar -> nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']["foo","afoo","bafoo","cbafoo","dcbafoo"]
>>>take 10 (scanl (+) 0 [1..])[0,1,3,6,10,15,21,28,36,45]
>>>take 1 (scanl undefined 'a' undefined)"a"
scanl1 :: (a -> a -> a) -> [a] -> [a] #
\(\mathcal{O}(n)\). scanl1 is a variant of scanl that has no starting
value argument:
scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...]
Examples
>>>scanl1 (+) [1..4][1,3,6,10]
>>>scanl1 (+) [][]
>>>scanl1 (-) [1..4][1,-1,-4,-8]
>>>scanl1 (&&) [True, False, True, True][True,False,False,False]
>>>scanl1 (||) [False, False, True, True][False,False,True,True]
>>>take 10 (scanl1 (+) [1..])[1,3,6,10,15,21,28,36,45,55]
>>>take 1 (scanl1 undefined ('a' : undefined))"a"
scanr :: (a -> b -> b) -> b -> [a] -> [b] #
\(\mathcal{O}(n)\). scanr is the right-to-left dual of scanl. Note that the order of parameters on the accumulating function are reversed compared to scanl.
Also note that
head (scanr f z xs) == foldr f z xs.
Examples
>>>scanr (+) 0 [1..4][10,9,7,4,0]
>>>scanr (+) 42 [][42]
>>>scanr (-) 100 [1..4][98,-97,99,-96,100]
>>>scanr (\nextChar reversedString -> nextChar : reversedString) "foo" ['a', 'b', 'c', 'd']["abcdfoo","bcdfoo","cdfoo","dfoo","foo"]
>>>force $ scanr (+) 0 [1..]*** Exception: stack overflow
scanr1 :: (a -> a -> a) -> [a] -> [a] #
\(\mathcal{O}(n)\). scanr1 is a variant of scanr that has no starting
value argument.
Examples
>>>scanr1 (+) [1..4][10,9,7,4]
>>>scanr1 (+) [][]
>>>scanr1 (-) [1..4][-2,3,-1,4]
>>>scanr1 (&&) [True, False, True, True][False,False,True,True]
>>>scanr1 (||) [True, True, False, False][True,True,False,False]
>>>force $ scanr1 (+) [1..]*** Exception: stack overflow
iterate :: (a -> a) -> a -> [a] #
iterate f x returns an infinite list of repeated applications
of f to x:
iterate f x == [x, f x, f (f x), ...]
Laziness
Note that iterate is lazy, potentially leading to thunk build-up if
the consumer doesn't force each iterate. See iterate' for a strict
variant of this function.
>>>take 1 $ iterate undefined 42[42]
Examples
>>>take 10 $ iterate not True[True,False,True,False,True,False,True,False,True,False]
>>>take 10 $ iterate (+3) 42[42,45,48,51,54,57,60,63,66,69]
iterate id == :repeat
>>>take 10 $ iterate id 1[1,1,1,1,1,1,1,1,1,1]
repeat x is an infinite list, with x the value of every element.
Examples
>>>take 10 $ repeat 17[17,17,17,17,17,17,17,17,17, 17]
>>>repeat undefined[*** Exception: Prelude.undefined
replicate :: Int -> a -> [a] #
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.
Examples
>>>replicate 0 True[]
>>>replicate (-1) True[]
>>>replicate 4 True[True,True,True,True]
takeWhile :: (a -> Bool) -> [a] -> [a] #
takeWhile, applied to a predicate p and a list xs, returns the
longest prefix (possibly empty) of xs of elements that satisfy p.
Laziness
>>>takeWhile (const False) undefined*** Exception: Prelude.undefined
>>>takeWhile (const False) (undefined : undefined)[]
>>>take 1 (takeWhile (const True) (1 : undefined))[1]
Examples
>>>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][]
take n, applied to a list xs, returns the prefix of xs
of length n, or xs itself if n >= .length xs
It is an instance of the more general genericTake,
in which n may be of any integral type.
Laziness
>>>take 0 undefined[]>>>take 2 (1 : 2 : undefined)[1,2]
Examples
>>>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][]
drop n xs returns the suffix of xs
after the first n elements, or [] if n >= .length xs
It is an instance of the more general genericDrop,
in which n may be of any integral type.
Examples
>>>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]
splitAt :: Int -> [a] -> ([a], [a]) #
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 is an instance of the more general genericSplitAt,
in which n may be of any integral type.
Laziness
It is equivalent to (
unless take n xs, drop n xs)n is _|_:
splitAt _|_ xs = _|_, not (_|_, _|_)).
The first component of the tuple is produced lazily:
>>>fst (splitAt 0 undefined)[]
>>>take 1 (fst (splitAt 10 (1 : undefined)))[1]
Examples
>>>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])
span :: (a -> Bool) -> [a] -> ([a], [a]) #
span, applied to a predicate p and a list xs, returns a tuple where
first element is the longest prefix (possibly empty) of xs of elements that
satisfy p and second element is the remainder of the list:
span p xs is equivalent to (, even if takeWhile p xs, dropWhile p xs)p is _|_.
Laziness
>>>span undefined []([],[])>>>fst (span (const False) undefined)*** Exception: Prelude.undefined>>>fst (span (const False) (undefined : undefined))[]>>>take 1 (fst (span (const True) (1 : undefined)))[1]
span produces the first component of the tuple lazily:
>>>take 10 (fst (span (const True) [1..]))[1,2,3,4,5,6,7,8,9,10]
Examples
>>>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]) #
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 p is equivalent to
and consequently to span (not . p)(,
even if takeWhile (not . p) xs, dropWhile (not . p) xs)p is _|_.
Laziness
>>>break undefined []([],[])
>>>fst (break (const True) undefined)*** Exception: Prelude.undefined
>>>fst (break (const True) (undefined : undefined))[]
>>>take 1 (fst (break (const False) (1 : undefined)))[1]
break produces the first component of the tuple lazily:
>>>take 10 (fst (break (const False) [1..]))[1,2,3,4,5,6,7,8,9,10]
Examples
>>>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],[])
\(\mathcal{O}(n)\). reverse xs returns the elements of xs in reverse order.
xs must be finite.
Laziness
reverse is lazy in its elements.
>>>head (reverse [undefined, 1])1
>>>reverse (1 : 2 : undefined)*** Exception: Prelude.undefined
Examples
>>>reverse [][]
>>>reverse [42][42]
>>>reverse [2,5,7][7,5,2]
>>>reverse [1..]* Hangs forever *
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c] #
\(\mathcal{O}(\min(m,n))\). zipWith generalises zip by zipping with the
function given as the first argument, instead of a tupling function.
zipWith (,) xs ys == zip xs ys zipWith f [x1,x2,x3..] [y1,y2,y3..] == [f x1 y1, f x2 y2, f x3 y3..]
zipWith is right-lazy:
>>>let f = undefined>>>zipWith f [] undefined[]
zipWith is capable of list fusion, but it is restricted to its
first list argument and its resulting list.
Examples
unzip :: [(a, b)] -> ([a], [b]) #
unzip transforms a list of pairs into a list of first components
and a list of second components.
Examples
>>>unzip []([],[])
>>>unzip [(1, 'a'), (2, 'b')]([1,2],"ab")
isPrefixOf :: Eq a => [a] -> [a] -> Bool #
\(\mathcal{O}(\min(m,n))\). The isPrefixOf function takes two lists and
returns True iff the first list is a prefix of the second.
Examples
>>>"Hello" `isPrefixOf` "Hello World!"True
>>>"Hello" `isPrefixOf` "Wello Horld!"False
For the result to be True, the first list must be finite;
False, however, results from any mismatch:
>>>[0..] `isPrefixOf` [1..]False
>>>[0..] `isPrefixOf` [0..99]False
>>>[0..99] `isPrefixOf` [0..]True
>>>[0..] `isPrefixOf` [0..]* Hangs forever *
isPrefixOf shortcuts when the first argument is empty:
>>>isPrefixOf [] undefinedTrue
intersperse :: a -> [a] -> [a] #
\(\mathcal{O}(n)\). The intersperse function takes an element and a list
and `intersperses' that element between the elements of the list.
Laziness
intersperse has the following properties
>>>take 1 (intersperse undefined ('a' : undefined))"a"
>>>take 2 (intersperse ',' ('a' : undefined))"a*** Exception: Prelude.undefined
Examples
>>>intersperse ',' "abcde""a,b,c,d,e"
>>>intersperse 1 [3, 4, 5][3,1,4,1,5]
intercalate :: [a] -> [[a]] -> [a] #
intercalate xs xss is equivalent to (.
It inserts the list concat (intersperse xs xss))xs in between the lists in xss and concatenates the
result.
Laziness
intercalate has the following properties:
>>>take 5 (intercalate undefined ("Lorem" : undefined))"Lorem"
>>>take 6 (intercalate ", " ("Lorem" : undefined))"Lorem*** Exception: Prelude.undefined
Examples
>>>intercalate ", " ["Lorem", "ipsum", "dolor"]"Lorem, ipsum, dolor"
>>>intercalate [0, 1] [[2, 3], [4, 5, 6], []][2,3,0,1,4,5,6,0,1]
>>>intercalate [1, 2, 3] [[], []][1,2,3]
genericLength :: Num i => [a] -> i #
\(\mathcal{O}(n)\). The genericLength function is an overloaded version
of length. In particular, instead of returning an Int, it returns any
type which is an instance of Num. It is, however, less efficient than
length.
Examples
>>>genericLength [1, 2, 3] :: Int3>>>genericLength [1, 2, 3] :: Float3.0
Users should take care to pick a return type that is wide enough to contain
the full length of the list. If the width is insufficient, the overflow
behaviour will depend on the (+) implementation in the selected Num
instance. The following example overflows because the actual list length
of 200 lies outside of the Int8 range of -128..127.
>>>genericLength [1..200] :: Int8-56
genericTake :: Integral i => i -> [a] -> [a] #
The genericTake function is an overloaded version of take, which
accepts any Integral value as the number of elements to take.
genericDrop :: Integral i => i -> [a] -> [a] #
The genericDrop function is an overloaded version of drop, which
accepts any Integral value as the number of elements to drop.
genericSplitAt :: Integral i => i -> [a] -> ([a], [a]) #
The genericSplitAt function is an overloaded version of splitAt, which
accepts any Integral value as the position at which to split.
genericReplicate :: Integral i => i -> a -> [a] #
The genericReplicate function is an overloaded version of replicate,
which accepts any Integral value as the number of repetitions to make.
group :: Eq a => [a] -> [[a]] #
The group function takes a list and returns a list of lists such
that the concatenation of the result is equal to the argument. Moreover,
each sublist in the result is non-empty, all elements are equal to the
first one, and consecutive equal elements of the input end up in the
same element of the output list.
group is a special case of groupBy, which allows the programmer to supply
their own equality test.
It's often preferable to use Data.List.NonEmpty.group,
which provides type-level guarantees of non-emptiness of inner lists.
A common idiom to squash repeating elements map head . group
is better served by
map Data.List.NonEmpty.head . Data.List.NonEmpty.group
because it avoids partial functions.
Examples
>>>group "Mississippi"["M","i","ss","i","ss","i","pp","i"]
>>>group [1, 1, 1, 2, 2, 3, 4, 5, 5][[1,1,1],[2,2],[3],[4],[5,5]]
The inits function returns all initial segments of the argument,
shortest first.
inits is semantically equivalent to ,
but under the hood uses a queue to amortize costs of map reverse . scanl (flip (:)) []reverse.
Laziness
Note that inits has the following strictness property:
inits (xs ++ _|_) = inits xs ++ _|_
In particular,
inits _|_ = [] : _|_
Examples
>>>inits "abc"["","a","ab","abc"]
>>>inits [][[]]
inits is productive on infinite lists:
>>>take 5 $ inits [1..][[],[1],[1,2],[1,2,3],[1,2,3,4]]
\(\mathcal{O}(n)\). The tails function returns all final segments of the
argument, longest first.
Laziness
Note that tails has the following strictness property:
tails _|_ = _|_ : _|_
>>>tails undefined[*** Exception: Prelude.undefined
>>>drop 1 (tails [undefined, 1, 2])[[1, 2], [2], []]
Examples
>>>tails "abc"["abc","bc","c",""]
>>>tails [1, 2, 3][[1,2,3],[2,3],[3],[]]
>>>tails [][[]]
subsequences :: [a] -> [[a]] #
The subsequences function returns the list of all subsequences of the argument.
Laziness
subsequences does not look ahead unless it must:
>>>take 1 (subsequences undefined)[[]]>>>take 2 (subsequences ('a' : undefined))["","a"]
Examples
>>>subsequences "abc"["","a","b","ab","c","ac","bc","abc"]
This function is productive on infinite inputs:
>>>take 8 $ subsequences ['a'..]["","a","b","ab","c","ac","bc","abc"]
permutations :: [a] -> [[a]] #
The permutations function returns the list of all permutations of the argument.
Note that the order of permutations is not lexicographic. It satisfies the following property:
map (take n) (take (product [1..n]) (permutations ([1..n] ++ undefined))) == permutations [1..n]
Laziness
The permutations function is maximally lazy:
for each n, the value of starts with those permutations
that permute permutations xs and keep take n xs.drop n xs
Examples
>>>permutations "abc"["abc","bac","cba","bca","cab","acb"]
>>>permutations [1, 2][[1,2],[2,1]]
>>>permutations [][[]]
This function is productive on infinite inputs:
>>>take 6 $ map (take 3) $ permutations ['a'..]["abc","bac","cba","bca","cab","acb"]
The sort function implements a stable sorting algorithm.
It is a special case of sortBy, which allows the programmer to supply
their own comparison function.
Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input.
The argument must be finite.
Examples
>>>sort [1,6,4,3,2,5][1,2,3,4,5,6]
>>>sort "haskell""aehklls"
>>>import Data.Semigroup(Arg(..))>>>sort [Arg ":)" 0, Arg ":D" 0, Arg ":)" 1, Arg ":3" 0, Arg ":D" 1][Arg ":)" 0,Arg ":)" 1,Arg ":3" 0,Arg ":D" 0,Arg ":D" 1]
Non-empty (and non-strict) list type.
Since: base-4.9.0.0
Constructors
| a :| [a] infixr 5 |
Instances
| MonadZip NonEmpty | Since: base-4.9.0.0 | ||||
| Foldable1 NonEmpty | Since: base-4.18.0.0 | ||||
Defined in Data.Foldable1 Methods fold1 :: Semigroup m => NonEmpty m -> m # foldMap1 :: Semigroup m => (a -> m) -> NonEmpty a -> m # foldMap1' :: Semigroup m => (a -> m) -> NonEmpty a -> m # toNonEmpty :: NonEmpty a -> NonEmpty a # maximum :: Ord a => NonEmpty a -> a # minimum :: Ord a => NonEmpty a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b # | |||||
| Eq1 NonEmpty | Since: base-4.10.0.0 | ||||
| Ord1 NonEmpty | Since: base-4.10.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Read1 NonEmpty | Since: base-4.10.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Show1 NonEmpty | Since: base-4.10.0.0 | ||||
| Applicative NonEmpty | Since: base-4.9.0.0 | ||||
| Functor NonEmpty | Since: base-4.9.0.0 | ||||
| Monad NonEmpty | Since: base-4.9.0.0 | ||||
| Foldable NonEmpty | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => NonEmpty m -> m # foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m # foldMap' :: Monoid m => (a -> m) -> NonEmpty a -> m # foldr :: (a -> b -> b) -> b -> NonEmpty a -> b # foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b # foldl :: (b -> a -> b) -> b -> NonEmpty a -> b # foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b # foldr1 :: (a -> a -> a) -> NonEmpty a -> a # foldl1 :: (a -> a -> a) -> NonEmpty a -> a # elem :: Eq a => a -> NonEmpty a -> Bool # maximum :: Ord a => NonEmpty a -> a # minimum :: Ord a => NonEmpty a -> a # | |||||
| Traversable NonEmpty | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Traversable | |||||
| Generic1 NonEmpty | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Semigroup (NonEmpty a) | Since: base-4.9.0.0 | ||||
| Generic (NonEmpty a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| IsList (NonEmpty a) | Since: base-4.9.0.0 | ||||
| Read a => Read (NonEmpty a) | Since: base-4.11.0.0 | ||||
| Show a => Show (NonEmpty a) | Since: base-4.11.0.0 | ||||
| Eq a => Eq (NonEmpty a) | Since: base-4.9.0.0 | ||||
| Ord a => Ord (NonEmpty a) | Since: base-4.9.0.0 | ||||
| type Rep1 NonEmpty | Since: base-4.6.0.0 | ||||
Defined in GHC.Internal.Generics type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 []))) | |||||
| type Rep (NonEmpty a) | Since: base-4.6.0.0 | ||||
Defined in GHC.Internal.Generics type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]))) | |||||
| type Item (NonEmpty a) | |||||
Defined in GHC.Internal.IsList | |||||
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
| MonadZip Maybe | Since: base-4.8.0.0 | ||||
| Eq1 Maybe | Since: base-4.9.0.0 | ||||
| Ord1 Maybe | Since: base-4.9.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Read1 Maybe | Since: base-4.9.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Show1 Maybe | Since: base-4.9.0.0 | ||||
| Alternative Maybe | Picks the leftmost Since: base-2.1 | ||||
| Applicative Maybe | Since: base-2.1 | ||||
| Functor Maybe | Since: base-2.1 | ||||
| Monad Maybe | Since: base-2.1 | ||||
| MonadPlus Maybe | Picks the leftmost Since: base-2.1 | ||||
| MonadFail Maybe | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Control.Monad.Fail | |||||
| Foldable Maybe | Since: base-2.1 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => Maybe m -> m # foldMap :: Monoid m => (a -> m) -> Maybe a -> m # foldMap' :: Monoid m => (a -> m) -> Maybe a -> m # foldr :: (a -> b -> b) -> b -> Maybe a -> b # foldr' :: (a -> b -> b) -> b -> Maybe a -> b # foldl :: (b -> a -> b) -> b -> Maybe a -> b # foldl' :: (b -> a -> b) -> b -> Maybe a -> b # foldr1 :: (a -> a -> a) -> Maybe a -> a # foldl1 :: (a -> a -> a) -> Maybe a -> a # elem :: Eq a => a -> Maybe a -> Bool # maximum :: Ord a => Maybe a -> a # minimum :: Ord a => Maybe a -> a # | |||||
| Traversable Maybe | Since: base-2.1 | ||||
| Generic1 Maybe | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Default (Maybe a) | |||||
Defined in Data.Default.Internal | |||||
| Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 | ||||
| Semigroup a => Semigroup (Maybe a) | Since: base-4.9.0.0 | ||||
| Generic (Maybe a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| SingKind a => SingKind (Maybe a) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Read a => Read (Maybe a) | Since: base-2.1 | ||||
| Show a => Show (Maybe a) | Since: base-2.1 | ||||
| Eq a => Eq (Maybe a) | Since: base-2.1 | ||||
| Ord a => Ord (Maybe a) | Since: base-2.1 | ||||
| SingI ('Nothing :: Maybe a) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| SingI a2 => SingI ('Just a2 :: Maybe a1) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| type Rep1 Maybe | Since: base-4.6.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| type DemoteRep (Maybe a) | |||||
Defined in GHC.Internal.Generics | |||||
| type Rep (Maybe a) | Since: base-4.6.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| data Sing (b :: Maybe a) | |||||
maybe :: b -> (a -> b) -> Maybe a -> b #
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 GHC.Internal.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""
fromMaybe :: a -> Maybe a -> a #
The fromMaybe function takes a default value and a Maybe
value. If the Maybe is Nothing, it returns the default value;
otherwise, it returns the value contained in the Maybe.
Examples
Basic usage:
>>>fromMaybe "" (Just "Hello, World!")"Hello, World!"
>>>fromMaybe "" Nothing""
Read an integer from a string using readMaybe. If we fail to
parse an integer, we want to return 0 by default:
>>>import GHC.Internal.Text.Read ( readMaybe )>>>fromMaybe 0 (readMaybe "5")5>>>fromMaybe 0 (readMaybe "")0
maybeToList :: Maybe a -> [a] #
The maybeToList function returns an empty list when given
Nothing or a singleton list when given Just.
Examples
Basic usage:
>>>maybeToList (Just 7)[7]
>>>maybeToList Nothing[]
One can use maybeToList to avoid pattern matching when combined
with a function that (safely) works on lists:
>>>import GHC.Internal.Text.Read ( readMaybe )>>>sum $ maybeToList (readMaybe "3")3>>>sum $ maybeToList (readMaybe "")0
listToMaybe :: [a] -> Maybe a #
The listToMaybe function returns Nothing on an empty list
or where Just aa is the first element of the list.
Examples
Basic usage:
>>>listToMaybe []Nothing
>>>listToMaybe [9]Just 9
>>>listToMaybe [1,2,3]Just 1
Composing maybeToList with listToMaybe should be the identity
on singleton/empty lists:
>>>maybeToList $ listToMaybe [5][5]>>>maybeToList $ listToMaybe [][]
But not on lists with more than one element:
>>>maybeToList $ listToMaybe [1,2,3][1]
catMaybes :: [Maybe a] -> [a] #
The catMaybes function takes a list of Maybes and returns
a list of all the Just values.
Examples
Basic usage:
>>>catMaybes [Just 1, Nothing, Just 3][1,3]
When constructing a list of Maybe values, catMaybes can be used
to return all of the "success" results (if the list is the result
of a map, then mapMaybe would be more appropriate):
>>>import GHC.Internal.Text.Read ( readMaybe )>>>[readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][Just 1,Nothing,Just 3]>>>catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][1,3]
mapMaybe :: (a -> Maybe b) -> [a] -> [b] #
The mapMaybe function is a version of map which can throw
out elements. In particular, the functional argument returns
something of type . If this is Maybe bNothing, no element
is added on to the result list. If it is , then Just bb is
included in the result list.
Examples
Using is a shortcut for mapMaybe f x
in most cases:catMaybes $ map f x
>>>import GHC.Internal.Text.Read ( readMaybe )>>>let readMaybeInt = readMaybe :: String -> Maybe Int>>>mapMaybe readMaybeInt ["1", "Foo", "3"][1,3]>>>catMaybes $ map readMaybeInt ["1", "Foo", "3"][1,3]
If we map the Just constructor, the entire list should be returned:
>>>mapMaybe Just [1,2,3][1,2,3]
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following:
- Right identity
x<>mempty= x- Left identity
mempty<>x = x- Associativity
x(<>(y<>z) = (x<>y)<>zSemigrouplaw)- Concatenation
mconcat=foldr(<>)mempty
You can alternatively define mconcat instead of mempty, in which case the
laws are:
- Unit
mconcat(purex) = x- Multiplication
mconcat(joinxss) =mconcat(fmapmconcatxss)- Subclass
mconcat(toListxs) =sconcatxs
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.
Methods
Identity of mappend
Examples
>>>"Hello world" <> mempty"Hello world"
>>>mempty <> [1, 2, 3][1,2,3]
An associative operation
NOTE: This method is redundant and has the default
implementation since base-4.11.0.0.
Should it be implemented manually, since mappend = (<>)mappend is a synonym for
(<>), it is expected that the two functions are defined the same
way. In a future GHC release mappend will be removed from Monoid.
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.
>>>mconcat ["Hello", " ", "Haskell", "!"]"Hello Haskell!"
Instances
| Monoid ByteArray | Since: base-4.17.0.0 |
| Monoid Builder | |
| Monoid ByteString | |
Defined in Data.ByteString.Internal.Type Methods mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
| Monoid ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
| Monoid ShortByteString | |
Defined in Data.ByteString.Short.Internal Methods mappend :: ShortByteString -> ShortByteString -> ShortByteString # mconcat :: [ShortByteString] -> ShortByteString # | |
| Monoid IntSet | |
| Monoid ExceptionContext | |
Defined in GHC.Internal.Exception.Context Methods mappend :: ExceptionContext -> ExceptionContext -> ExceptionContext # mconcat :: [ExceptionContext] -> ExceptionContext # | |
| Monoid Ordering | Since: base-2.1 |
| Monoid Text | |
| Monoid Builder | |
| Monoid Text | |
| Monoid StrictTextBuilder | |
Defined in Data.Text.Internal.StrictBuilder Methods mappend :: StrictTextBuilder -> StrictTextBuilder -> StrictTextBuilder # mconcat :: [StrictTextBuilder] -> StrictTextBuilder # | |
| Monoid () | Since: base-2.1 |
| Monoid (Comparison a) |
mempty :: Comparison a mempty = Comparison _ _ -> EQ |
Defined in Data.Functor.Contravariant Methods mempty :: Comparison a # mappend :: Comparison a -> Comparison a -> Comparison a # mconcat :: [Comparison a] -> Comparison a # | |
| Monoid (Equivalence a) |
mempty :: Equivalence a mempty = Equivalence _ _ -> True |
Defined in Data.Functor.Contravariant Methods mempty :: Equivalence a # mappend :: Equivalence a -> Equivalence a -> Equivalence a # mconcat :: [Equivalence a] -> Equivalence a # | |
| Monoid (Predicate a) |
mempty :: Predicate a mempty = _ -> True |
| (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 m => Monoid (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
| Monoid (IntMap a) | |
| Monoid (Seq a) | |
| Monoid (MergeSet a) | |
| Ord a => Monoid (Set a) | |
| Monoid a => Monoid (Identity a) | Since: base-4.9.0.0 |
| Monoid a => Monoid (Down a) | Since: base-4.11.0.0 |
| (Generic a, Monoid (Rep a ())) => Monoid (Generically a) | Since: base-4.17.0.0 |
Defined in GHC.Internal.Generics Methods mempty :: Generically a # mappend :: Generically a -> Generically a -> Generically a # mconcat :: [Generically a] -> Generically a # | |
| Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
| Monoid a => Monoid (IO 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 |
| Monoid a => Monoid (Solo a) | Since: base-4.15 |
| Monoid [a] | Since: base-2.1 |
| Monoid a => Monoid (Op a b) |
mempty :: Op a b mempty = Op _ -> mempty |
| Ord k => Monoid (Map k v) | |
| Monoid (Proxy s) | Since: base-4.7.0.0 |
| Monoid (U1 p) | Since: base-4.12.0.0 |
| (Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1 |
| Monoid b => Monoid (a -> b) | Since: base-2.1 |
| Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
| Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0 |
| (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1 |
| (Monoid (f a), Monoid (g a)) => Monoid (Product f g a) | Since: base-4.16.0.0 |
| (Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) | Since: base-4.12.0.0 |
| Monoid c => Monoid (K1 i c p) | Since: base-4.12.0.0 |
| (Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | Since: base-2.1 |
| Monoid (f (g a)) => Monoid (Compose f g a) | Since: base-4.16.0.0 |
| Monoid (f (g p)) => Monoid ((f :.: g) p) | Since: base-4.12.0.0 |
| Monoid (f p) => Monoid (M1 i c f p) | Since: base-4.12.0.0 |
| (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | Since: base-2.1 |
Instances
| Default Ordering | |
Defined in Data.Default.Internal | |
| Monoid Ordering | Since: base-2.1 |
| Semigroup Ordering | Since: base-4.9.0.0 |
| Bounded Ordering | Since: base-2.1 |
| Enum Ordering | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| Generic Ordering | |
Defined in GHC.Internal.Generics | |
| Read Ordering | Since: base-2.1 |
| Show Ordering | Since: base-2.1 |
| Eq Ordering | |
| Ord Ordering | |
Defined in GHC.Classes | |
| type Rep Ordering | Since: base-4.6.0.0 |
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.
Ord, as defined by the Haskell report, implements a total order and has the
following properties:
- Comparability
x <= y || y <= x=True- Transitivity
- if
x <= y && y <= z=True, thenx <= z=True - Reflexivity
x <= x=True- Antisymmetry
- if
x <= y && y <= x=True, thenx == y=True
The following operator interactions are expected to hold:
x >= y=y <= xx < y=x <= y && x /= yx > y=y < xx < y=compare x y == LTx > y=compare x y == GTx == y=compare x y == EQmin x y == if x <= y then x else y=Truemax x y == if x >= y then x else y=True
Note that (7.) and (8.) do not require min and max to return either of
their arguments. The result is merely required to equal one of the
arguments in terms of (==).
Minimal complete definition: either compare or <=.
Using compare can be more efficient for complex types.
Methods
compare :: a -> a -> Ordering #
(<) :: a -> a -> Bool infix 4 #
(<=) :: a -> a -> Bool infix 4 #
(>) :: a -> a -> Bool infix 4 #
Instances
| Ord ByteArray | Non-lexicographic ordering. This compares the lengths of the byte arrays first and uses a lexicographic ordering if the lengths are equal. Subject to change between major versions. Since: base-4.17.0.0 |
| Ord ByteString | |
Defined in Data.ByteString.Internal.Type Methods compare :: ByteString -> ByteString -> Ordering # (<) :: ByteString -> ByteString -> Bool # (<=) :: ByteString -> ByteString -> Bool # (>) :: ByteString -> ByteString -> Bool # (>=) :: ByteString -> ByteString -> Bool # max :: ByteString -> ByteString -> ByteString # min :: ByteString -> ByteString -> ByteString # | |
| Ord ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods compare :: ByteString -> ByteString -> Ordering # (<) :: ByteString -> ByteString -> Bool # (<=) :: ByteString -> ByteString -> Bool # (>) :: ByteString -> ByteString -> Bool # (>=) :: ByteString -> ByteString -> Bool # max :: ByteString -> ByteString -> ByteString # min :: ByteString -> ByteString -> ByteString # | |
| Ord ShortByteString | Lexicographic order. |
Defined in Data.ByteString.Short.Internal Methods compare :: ShortByteString -> ShortByteString -> Ordering # (<) :: ShortByteString -> ShortByteString -> Bool # (<=) :: ShortByteString -> ShortByteString -> Bool # (>) :: ShortByteString -> ShortByteString -> Bool # (>=) :: ShortByteString -> ShortByteString -> Bool # max :: ShortByteString -> ShortByteString -> ShortByteString # min :: ShortByteString -> ShortByteString -> ShortByteString # | |
| Ord IntSet | |
| Ord BigNat | |
| Ord Void | Since: base-4.8.0.0 |
| Ord SomeTypeRep | |
Defined in GHC.Internal.Data.Typeable.Internal Methods compare :: SomeTypeRep -> SomeTypeRep -> Ordering # (<) :: SomeTypeRep -> SomeTypeRep -> Bool # (<=) :: SomeTypeRep -> SomeTypeRep -> Bool # (>) :: SomeTypeRep -> SomeTypeRep -> Bool # (>=) :: SomeTypeRep -> SomeTypeRep -> Bool # max :: SomeTypeRep -> SomeTypeRep -> SomeTypeRep # min :: SomeTypeRep -> SomeTypeRep -> SomeTypeRep # | |
| Ord ArithException | Since: base-3.0 |
Defined in GHC.Internal.Exception.Type Methods compare :: ArithException -> ArithException -> Ordering # (<) :: ArithException -> ArithException -> Bool # (<=) :: ArithException -> ArithException -> Bool # (>) :: ArithException -> ArithException -> Bool # (>=) :: ArithException -> ArithException -> Bool # max :: ArithException -> ArithException -> ArithException # min :: ArithException -> ArithException -> ArithException # | |
| Ord Associativity | Since: base-4.6.0.0 |
Defined in GHC.Internal.Generics Methods compare :: Associativity -> Associativity -> Ordering # (<) :: Associativity -> Associativity -> Bool # (<=) :: Associativity -> Associativity -> Bool # (>) :: Associativity -> Associativity -> Bool # (>=) :: Associativity -> Associativity -> Bool # max :: Associativity -> Associativity -> Associativity # min :: Associativity -> Associativity -> Associativity # | |
| Ord DecidedStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods compare :: DecidedStrictness -> DecidedStrictness -> Ordering # (<) :: DecidedStrictness -> DecidedStrictness -> Bool # (<=) :: DecidedStrictness -> DecidedStrictness -> Bool # (>) :: DecidedStrictness -> DecidedStrictness -> Bool # (>=) :: DecidedStrictness -> DecidedStrictness -> Bool # max :: DecidedStrictness -> DecidedStrictness -> DecidedStrictness # min :: DecidedStrictness -> DecidedStrictness -> DecidedStrictness # | |
| Ord Fixity | Since: base-4.6.0.0 |
| Ord SourceStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods compare :: SourceStrictness -> SourceStrictness -> Ordering # (<) :: SourceStrictness -> SourceStrictness -> Bool # (<=) :: SourceStrictness -> SourceStrictness -> Bool # (>) :: SourceStrictness -> SourceStrictness -> Bool # (>=) :: SourceStrictness -> SourceStrictness -> Bool # max :: SourceStrictness -> SourceStrictness -> SourceStrictness # min :: SourceStrictness -> SourceStrictness -> SourceStrictness # | |
| Ord SourceUnpackedness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods compare :: SourceUnpackedness -> SourceUnpackedness -> Ordering # (<) :: SourceUnpackedness -> SourceUnpackedness -> Bool # (<=) :: SourceUnpackedness -> SourceUnpackedness -> Bool # (>) :: SourceUnpackedness -> SourceUnpackedness -> Bool # (>=) :: SourceUnpackedness -> SourceUnpackedness -> Bool # max :: SourceUnpackedness -> SourceUnpackedness -> SourceUnpackedness # min :: SourceUnpackedness -> SourceUnpackedness -> SourceUnpackedness # | |
| Ord Int16 | Since: base-2.1 |
| Ord Int32 | Since: base-2.1 |
| Ord Int64 | Since: base-2.1 |
| Ord Int8 | Since: base-2.1 |
| Ord SomeChar | |
Defined in GHC.Internal.TypeLits | |
| Ord SomeSymbol | Since: base-4.7.0.0 |
Defined in GHC.Internal.TypeLits Methods compare :: SomeSymbol -> SomeSymbol -> Ordering # (<) :: SomeSymbol -> SomeSymbol -> Bool # (<=) :: SomeSymbol -> SomeSymbol -> Bool # (>) :: SomeSymbol -> SomeSymbol -> Bool # (>=) :: SomeSymbol -> SomeSymbol -> Bool # max :: SomeSymbol -> SomeSymbol -> SomeSymbol # min :: SomeSymbol -> SomeSymbol -> SomeSymbol # | |
| Ord SomeNat | Since: base-4.7.0.0 |
Defined in GHC.Internal.TypeNats | |
| Ord Word16 | Since: base-2.1 |
| Ord Word32 | Since: base-2.1 |
| Ord Word64 | Since: base-2.1 |
| Ord Word8 | Since: base-2.1 |
| Ord Ordering | |
Defined in GHC.Classes | |
| Ord TyCon | |
| Ord I8 | |
| Ord Text | |
| Ord Builder | |
Defined in Data.Text.Internal.Builder | |
| Ord Text | |
| Ord Integer | |
| Ord Natural | |
| Ord () | |
| Ord Bool | |
| Ord Char | |
| Ord Double | IEEE 754 IEEE 754-2008, section 5.11 requires that if at least one of arguments of
IEEE 754-2008, section 5.10 defines Thus, users must be extremely cautious when using Moving further, the behaviour of IEEE 754-2008 compliant |
| Ord Float | See |
| Ord Int | |
| Ord Word | |
| Ord a => Ord (First a) | Since: base-4.9.0.0 |
| Ord a => Ord (Last a) | Since: base-4.9.0.0 |
| Ord a => Ord (Max a) | Since: base-4.9.0.0 |
| Ord a => Ord (Min a) | Since: base-4.9.0.0 |
| Ord m => Ord (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods compare :: WrappedMonoid m -> WrappedMonoid m -> Ordering # (<) :: WrappedMonoid m -> WrappedMonoid m -> Bool # (<=) :: WrappedMonoid m -> WrappedMonoid m -> Bool # (>) :: WrappedMonoid m -> WrappedMonoid m -> Bool # (>=) :: WrappedMonoid m -> WrappedMonoid m -> Bool # max :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # min :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # | |
| Ord a => Ord (IntMap a) | |
Defined in Data.IntMap.Internal | |
| Ord a => Ord (Seq a) | |
| Ord a => Ord (ViewL a) | |
Defined in Data.Sequence.Internal | |
| Ord a => Ord (ViewR a) | |
Defined in Data.Sequence.Internal | |
| Ord a => Ord (Intersection a) | |
Defined in Data.Set.Internal Methods compare :: Intersection a -> Intersection a -> Ordering # (<) :: Intersection a -> Intersection a -> Bool # (<=) :: Intersection a -> Intersection a -> Bool # (>) :: Intersection a -> Intersection a -> Bool # (>=) :: Intersection a -> Intersection a -> Bool # max :: Intersection a -> Intersection a -> Intersection a # min :: Intersection a -> Intersection a -> Intersection a # | |
| Ord a => Ord (Set a) | |
| Ord a => Ord (Tree a) | Since: containers-0.6.5 |
| Ord a => Ord (NonEmpty a) | Since: base-4.9.0.0 |
| Ord a => Ord (Identity a) | Since: base-4.8.0.0 |
Defined in GHC.Internal.Data.Functor.Identity | |
| Ord a => Ord (Down a) | Since: base-4.6.0.0 |
| Ord a => Ord (ZipList a) | Since: base-4.7.0.0 |
| Ord p => Ord (Par1 p) | Since: base-4.7.0.0 |
| Integral a => Ord (Ratio a) | Since: base-2.0.1 |
| Ord (SChar c) | Since: base-4.19.0.0 |
Defined in GHC.Internal.TypeLits | |
| Ord (SSymbol s) | Since: base-4.19.0.0 |
| Ord (SNat n) | Since: base-4.19.0.0 |
| Ord a => Ord (Stream a) | |
Defined in Data.Text.Internal.Fusion.Types | |
| Ord a => Ord (Maybe a) | Since: base-2.1 |
| Ord a => Ord (Solo a) | |
| Ord a => Ord [a] | |
| Ord (Fixed a) | Since: base-2.1 |
| Ord a => Ord (Arg a b) | Since: base-4.9.0.0 |
| (Ord k, Ord v) => Ord (Map k v) | |
| (Ord a, Ord b) => Ord (Either a b) | Since: base-2.1 |
Defined in GHC.Internal.Data.Either | |
| Ord (Proxy s) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Proxy | |
| Ord (TypeRep a) | Since: base-4.4.0.0 |
Defined in GHC.Internal.Data.Typeable.Internal | |
| Ord (U1 p) | Since: base-4.7.0.0 |
| Ord (V1 p) | Since: base-4.9.0.0 |
| (Ord a, Ord b) => Ord (a, b) | |
| Ord a => Ord (Const a b) | Since: base-4.9.0.0 |
| Ord (a :~: b) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Type.Equality | |
| (Generic1 f, Ord (Rep1 f a)) => Ord (Generically1 f a) | Since: base-4.18.0.0 |
Defined in GHC.Internal.Generics Methods compare :: Generically1 f a -> Generically1 f a -> Ordering # (<) :: Generically1 f a -> Generically1 f a -> Bool # (<=) :: Generically1 f a -> Generically1 f a -> Bool # (>) :: Generically1 f a -> Generically1 f a -> Bool # (>=) :: Generically1 f a -> Generically1 f a -> Bool # max :: Generically1 f a -> Generically1 f a -> Generically1 f a # min :: Generically1 f a -> Generically1 f a -> Generically1 f a # | |
| Ord (f p) => Ord (Rec1 f p) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Generics | |
| Ord (URec (Ptr ()) p) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods compare :: URec (Ptr ()) p -> URec (Ptr ()) p -> Ordering # (<) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (<=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # (>=) :: URec (Ptr ()) p -> URec (Ptr ()) p -> Bool # max :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # min :: URec (Ptr ()) p -> URec (Ptr ()) p -> URec (Ptr ()) p # | |
| Ord (URec Char p) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
| Ord (URec Double p) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods compare :: URec Double p -> URec Double p -> Ordering # (<) :: URec Double p -> URec Double p -> Bool # (<=) :: URec Double p -> URec Double p -> Bool # (>) :: URec Double p -> URec Double p -> Bool # (>=) :: URec Double p -> URec Double p -> Bool # | |
| Ord (URec Float p) | |
Defined in GHC.Internal.Generics | |
| Ord (URec Int p) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
| Ord (URec Word p) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
| (Ord a, Ord b, Ord c) => Ord (a, b, c) | |
| (Ord (f a), Ord (g a)) => Ord (Product f g a) | Since: base-4.18.0.0 |
Defined in Data.Functor.Product Methods compare :: Product f g a -> Product f g a -> Ordering # (<) :: Product f g a -> Product f g a -> Bool # (<=) :: Product f g a -> Product f g a -> Bool # (>) :: Product f g a -> Product f g a -> Bool # (>=) :: Product f g a -> Product f g a -> Bool # | |
| (Ord (f a), Ord (g a)) => Ord (Sum f g a) | Since: base-4.18.0.0 |
| Ord (a :~~: b) | Since: base-4.10.0.0 |
Defined in GHC.Internal.Data.Type.Equality | |
| (Ord (f p), Ord (g p)) => Ord ((f :*: g) p) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Generics | |
| (Ord (f p), Ord (g p)) => Ord ((f :+: g) p) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Generics | |
| Ord c => Ord (K1 i c p) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Generics | |
| (Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d) | |
Defined in GHC.Classes | |
| Ord (f (g a)) => Ord (Compose f g a) | Since: base-4.18.0.0 |
Defined in Data.Functor.Compose Methods compare :: Compose f g a -> Compose f g a -> Ordering # (<) :: Compose f g a -> Compose f g a -> Bool # (<=) :: Compose f g a -> Compose f g a -> Bool # (>) :: Compose f g a -> Compose f g a -> Bool # (>=) :: Compose f g a -> Compose f g a -> Bool # | |
| Ord (f (g p)) => Ord ((f :.: g) p) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Generics | |
| Ord (f p) => Ord (M1 i c f p) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Generics | |
| (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 # (<) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool # (<=) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool # (>) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool # (>=) :: (a, b, c, d, e) -> (a, b, c, d, e) -> Bool # max :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) # min :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) # | |
| (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 # (<) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool # (<=) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool # (>) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool # (>=) :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> Bool # max :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) # min :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) # | |
| (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 # (<) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool # (<=) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool # (>) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool # (>=) :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> Bool # max :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) # min :: (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) -> (a, b, c, d, e, f, g) # | |
| (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 # (<) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool # (<=) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool # (>) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool # (>=) :: (a, b, c, d, e, f, g, h) -> (a, b, c, d, e, f, g, h) -> Bool # 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) # 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) # | |
| (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 # (<) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool # (<=) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool # (>) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool # (>=) :: (a, b, c, d, e, f, g, h, i) -> (a, b, c, d, e, f, g, h, i) -> Bool # 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) # 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) # | |
| (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 # (<) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool # (<=) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool # (>) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool # (>=) :: (a, b, c, d, e, f, g, h, i, j) -> (a, b, c, d, e, f, g, h, i, j) -> Bool # 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) # 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) # | |
| (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 # (<) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool # (<=) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool # (>) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool # (>=) :: (a, b, c, d, e, f, g, h, i, j, k) -> (a, b, c, d, e, f, g, h, i, j, k) -> Bool # 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) # 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) # | |
| (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 # (<) :: (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 # (<=) :: (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 # (>) :: (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 # (>=) :: (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 # 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) # 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) # | |
| (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 # (<) :: (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 # (<=) :: (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 # (>) :: (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 # (>=) :: (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 # 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) # 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) # | |
| (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 # (<) :: (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 # (<=) :: (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 # (>) :: (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 # (>=) :: (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 # 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) # 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) # | |
| (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 # (<) :: (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 # (<=) :: (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 # (>) :: (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 # (>=) :: (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 # 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) # 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) # | |
The Down type allows you to reverse sort order conveniently. A value of type
contains a value of type Down aa (represented as ).Down a
If a has an instance associated with it then comparing two
values thus wrapped will give you the opposite of their normal sort order.
This is particularly useful when sorting in generalised list comprehensions,
as in: Ordthen sortWith by .Down x
>>>compare True FalseGT
>>>compare (Down True) (Down False)LT
If a has a instance then the wrapped instance also respects
the reversed ordering by exchanging the values of Bounded and
minBound.maxBound
>>>minBound :: Int-9223372036854775808
>>>minBound :: Down IntDown 9223372036854775807
All other instances of behave as they do for Down aa.
Since: base-4.6.0.0
Instances
| MonadZip Down | Since: base-4.12.0.0 | ||||
| Foldable1 Down | Since: base-4.18.0.0 | ||||
Defined in Data.Foldable1 Methods fold1 :: Semigroup m => Down m -> m # foldMap1 :: Semigroup m => (a -> m) -> Down a -> m # foldMap1' :: Semigroup m => (a -> m) -> Down a -> m # toNonEmpty :: Down a -> NonEmpty a # maximum :: Ord a => Down a -> a # minimum :: Ord a => Down a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Down a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Down a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Down a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Down a -> b # | |||||
| Eq1 Down | Since: base-4.12.0.0 | ||||
| Ord1 Down | Since: base-4.12.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Read1 Down | Since: base-4.12.0.0 | ||||
Defined in Data.Functor.Classes | |||||
| Show1 Down | Since: base-4.12.0.0 | ||||
| Applicative Down | Since: base-4.11.0.0 | ||||
| Functor Down | Since: base-4.11.0.0 | ||||
| Monad Down | Since: base-4.11.0.0 | ||||
| Foldable Down | Since: base-4.12.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => Down m -> m # foldMap :: Monoid m => (a -> m) -> Down a -> m # foldMap' :: Monoid m => (a -> m) -> Down a -> m # foldr :: (a -> b -> b) -> b -> Down a -> b # foldr' :: (a -> b -> b) -> b -> Down a -> b # foldl :: (b -> a -> b) -> b -> Down a -> b # foldl' :: (b -> a -> b) -> b -> Down a -> b # foldr1 :: (a -> a -> a) -> Down a -> a # foldl1 :: (a -> a -> a) -> Down a -> a # elem :: Eq a => a -> Down a -> Bool # maximum :: Ord a => Down a -> a # | |||||
| Traversable Down | Since: base-4.12.0.0 | ||||
| Generic1 Down | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Monoid a => Monoid (Down a) | Since: base-4.11.0.0 | ||||
| Semigroup a => Semigroup (Down a) | Since: base-4.11.0.0 | ||||
| Bits a => Bits (Down a) | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Data.Ord Methods (.&.) :: Down a -> Down a -> Down a # (.|.) :: Down a -> Down a -> Down a # xor :: Down a -> Down a -> Down a # complement :: Down a -> Down a # shift :: Down a -> Int -> Down a # rotate :: Down a -> Int -> Down a # setBit :: Down a -> Int -> Down a # clearBit :: Down a -> Int -> Down a # complementBit :: Down a -> Int -> Down a # testBit :: Down a -> Int -> Bool # bitSizeMaybe :: Down a -> Maybe Int # shiftL :: Down a -> Int -> Down a # unsafeShiftL :: Down a -> Int -> Down a # shiftR :: Down a -> Int -> Down a # unsafeShiftR :: Down a -> Int -> Down a # rotateL :: Down a -> Int -> Down a # | |||||
| FiniteBits a => FiniteBits (Down a) | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Data.Ord Methods finiteBitSize :: Down a -> Int # countLeadingZeros :: Down a -> Int # countTrailingZeros :: Down a -> Int # | |||||
| Bounded a => Bounded (Down a) | Swaps Since: base-4.14.0.0 | ||||
| (Enum a, Bounded a, Eq a) => Enum (Down a) | Swaps Since: base-4.18.0.0 | ||||
Defined in GHC.Internal.Data.Ord | |||||
| Floating a => Floating (Down a) | Since: base-4.14.0.0 | ||||
| RealFloat a => RealFloat (Down a) | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Data.Ord Methods floatRadix :: Down a -> Integer # floatDigits :: Down a -> Int # floatRange :: Down a -> (Int, Int) # decodeFloat :: Down a -> (Integer, Int) # encodeFloat :: Integer -> Int -> Down a # significand :: Down a -> Down a # scaleFloat :: Int -> Down a -> Down a # isInfinite :: Down a -> Bool # isDenormalized :: Down a -> Bool # isNegativeZero :: Down a -> Bool # | |||||
| Storable a => Storable (Down a) | Since: base-4.14.0.0 | ||||
| Generic (Down a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Ix a => Ix (Down a) | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Data.Ord | |||||
| Num a => Num (Down a) | Since: base-4.11.0.0 | ||||
| Read a => Read (Down a) | This instance would be equivalent to the derived instances of the
Since: base-4.7.0.0 | ||||
| Fractional a => Fractional (Down a) | Since: base-4.14.0.0 | ||||
| Real a => Real (Down a) | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Data.Ord Methods toRational :: Down a -> Rational # | |||||
| RealFrac a => RealFrac (Down a) | Since: base-4.14.0.0 | ||||
| Show a => Show (Down a) | This instance would be equivalent to the derived instances of the
Since: base-4.7.0.0 | ||||
| Eq a => Eq (Down a) | Since: base-4.6.0.0 | ||||
| Ord a => Ord (Down a) | Since: base-4.6.0.0 | ||||
| type Rep1 Down | Since: base-4.12.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| type Rep (Down a) | Since: base-4.12.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
comparing :: Ord a => (b -> a) -> b -> b -> Ordering #
comparing p x y = compare (p x) (p y)
Useful combinator for use in conjunction with the xxxBy family
of functions from Data.List, for example:
... sortBy (comparing fst) ...
Proxy is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically, is a safer alternative to the
Proxy :: Proxy a idiom.undefined :: a
>>>Proxy :: Proxy (Void, Int -> Int)Proxy
Proxy can even hold types of higher kinds,
>>>Proxy :: Proxy EitherProxy
>>>Proxy :: Proxy FunctorProxy
>>>Proxy :: Proxy complicatedStructureProxy
Constructors
| Proxy |
Instances
| Generic1 (Proxy :: k -> Type) | |
Defined in GHC.Internal.Generics | |
| MonadZip (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
| Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
| Show1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| Contravariant (Proxy :: Type -> Type) | |
| Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
| Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldMap' :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
| Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Default (Proxy a) | |
Defined in Data.Default.Internal | |
| Monoid (Proxy s) | Since: base-4.7.0.0 |
| Semigroup (Proxy s) | Since: base-4.9.0.0 |
| Bounded (Proxy t) | Since: base-4.7.0.0 |
| Enum (Proxy s) | Since: base-4.7.0.0 |
| Generic (Proxy t) | |
Defined in GHC.Internal.Generics | |
| Ix (Proxy s) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Proxy | |
| Read (Proxy t) | Since: base-4.7.0.0 |
| Show (Proxy s) | Since: base-4.7.0.0 |
| Eq (Proxy s) | Since: base-4.7.0.0 |
| Ord (Proxy s) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Proxy | |
| type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
| type Rep (Proxy t) | Since: base-4.6.0.0 |
The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
You can alternatively define sconcat instead of (<>), in which case the
laws are:
Since: base-4.9.0.0
Methods
(<>) :: a -> a -> a infixr 6 #
An associative operation.
Examples
>>>[1,2,3] <> [4,5,6][1,2,3,4,5,6]
>>>Just [1, 2, 3] <> Just [4, 5, 6]Just [1,2,3,4,5,6]
>>>putStr "Hello, " <> putStrLn "World!"Hello, World!
Reduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
Examples
For the following examples, we will assume that we have:
>>>import Data.List.NonEmpty (NonEmpty (..))
>>>sconcat $ "Hello" :| [" ", "Haskell", "!"]"Hello Haskell!"
>>>sconcat $ Just [1, 2, 3] :| [Nothing, Just [4, 5, 6]]Just [1,2,3,4,5,6]
>>>sconcat $ Left 1 :| [Right 2, Left 3, Right 4]Right 2
stimes :: Integral b => b -> a -> a #
Repeat a value n times.
The default definition will raise an exception for a multiplier that is <= 0.
This may be overridden with an implementation that is total. For monoids
it is preferred to use stimesMonoid.
By making this a member of the class, idempotent semigroups
and monoids can upgrade this to execute in \(\mathcal{O}(1)\) by
picking stimes = or stimesIdempotentstimes =
respectively.stimesIdempotentMonoid
Examples
>>>stimes 4 [1][1,1,1,1]
>>>stimes 5 (putStr "hi!")hi!hi!hi!hi!hi!
>>>stimes 3 (Right ":)")Right ":)"
Instances
| Semigroup ByteArray | Since: base-4.17.0.0 |
| Semigroup Builder | |
| Semigroup ByteString | |
Defined in Data.ByteString.Internal.Type Methods (<>) :: ByteString -> ByteString -> ByteString # sconcat :: NonEmpty ByteString -> ByteString # stimes :: Integral b => b -> ByteString -> ByteString # | |
| Semigroup ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods (<>) :: ByteString -> ByteString -> ByteString # sconcat :: NonEmpty ByteString -> ByteString # stimes :: Integral b => b -> ByteString -> ByteString # | |
| Semigroup ShortByteString | |
Defined in Data.ByteString.Short.Internal Methods (<>) :: ShortByteString -> ShortByteString -> ShortByteString # sconcat :: NonEmpty ShortByteString -> ShortByteString # stimes :: Integral b => b -> ShortByteString -> ShortByteString # | |
| Semigroup IntSet | Since: containers-0.5.7 |
| Semigroup Void | Since: base-4.9.0.0 |
| Semigroup ExceptionContext | |
Defined in GHC.Internal.Exception.Context Methods (<>) :: ExceptionContext -> ExceptionContext -> ExceptionContext # sconcat :: NonEmpty ExceptionContext -> ExceptionContext # stimes :: Integral b => b -> ExceptionContext -> ExceptionContext # | |
| Semigroup Ordering | Since: base-4.9.0.0 |
| Semigroup Text | Beware: Since: text-1.2.2.0 |
| Semigroup Builder | |
| Semigroup Text | Since: text-1.2.2.0 |
| Semigroup StrictTextBuilder | Concatenation of |
Defined in Data.Text.Internal.StrictBuilder Methods (<>) :: StrictTextBuilder -> StrictTextBuilder -> StrictTextBuilder # sconcat :: NonEmpty StrictTextBuilder -> StrictTextBuilder # stimes :: Integral b => b -> StrictTextBuilder -> StrictTextBuilder # | |
| Semigroup () | Since: base-4.9.0.0 |
| Semigroup (FromMaybe b) | |
| Semigroup a => Semigroup (JoinWith a) | |
| Semigroup (NonEmptyDList a) | |
| Semigroup (Comparison a) |
(<>) :: Comparison a -> Comparison a -> Comparison a Comparison cmp <> Comparison cmp' = Comparison a a' -> cmp a a' <> cmp a a' |
Defined in Data.Functor.Contravariant Methods (<>) :: Comparison a -> Comparison a -> Comparison a # sconcat :: NonEmpty (Comparison a) -> Comparison a # stimes :: Integral b => b -> Comparison a -> Comparison a # | |
| Semigroup (Equivalence a) |
(<>) :: Equivalence a -> Equivalence a -> Equivalence a Equivalence equiv <> Equivalence equiv' = Equivalence a b -> equiv a b && equiv' a b |
Defined in Data.Functor.Contravariant Methods (<>) :: Equivalence a -> Equivalence a -> Equivalence a # sconcat :: NonEmpty (Equivalence a) -> Equivalence a # stimes :: Integral b => b -> Equivalence a -> Equivalence a # | |
| Semigroup (Predicate a) |
(<>) :: Predicate a -> Predicate a -> Predicate a Predicate pred <> Predicate pred' = Predicate a -> pred a && pred' a |
| Semigroup (First a) | Since: base-4.9.0.0 |
| Semigroup (Last 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 |
| Monoid m => Semigroup (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods (<>) :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # sconcat :: NonEmpty (WrappedMonoid m) -> WrappedMonoid m # stimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m # | |
| Semigroup (IntMap a) | Since: containers-0.5.7 |
| Semigroup (Seq a) | Since: containers-0.5.7 |
| Ord a => Semigroup (Intersection a) | |
Defined in Data.Set.Internal Methods (<>) :: Intersection a -> Intersection a -> Intersection a # sconcat :: NonEmpty (Intersection a) -> Intersection a # stimes :: Integral b => b -> Intersection a -> Intersection a # | |
| Semigroup (MergeSet a) | |
| Ord a => Semigroup (Set a) | Since: containers-0.5.7 |
| Semigroup (NonEmpty a) | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Identity a) | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Down a) | Since: base-4.11.0.0 |
| (Generic a, Semigroup (Rep a ())) => Semigroup (Generically a) | Since: base-4.17.0.0 |
Defined in GHC.Internal.Generics Methods (<>) :: Generically a -> Generically a -> Generically a # sconcat :: NonEmpty (Generically a) -> Generically a # stimes :: Integral b => b -> Generically a -> Generically a # | |
| Semigroup p => Semigroup (Par1 p) | Since: base-4.12.0.0 |
| Semigroup a => Semigroup (IO a) | Since: base-4.10.0.0 |
| Semigroup a => Semigroup (Maybe a) | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Solo a) | Since: base-4.15 |
| Semigroup [a] | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Op a b) |
(<>) :: Op a b -> Op a b -> Op a b Op f <> Op g = Op a -> f a <> g a |
| Ord k => Semigroup (Map k v) | |
| Semigroup (Either a b) | Since: base-4.9.0.0 |
| Semigroup (Proxy s) | Since: base-4.9.0.0 |
| Semigroup (U1 p) | Since: base-4.12.0.0 |
| Semigroup (V1 p) | Since: base-4.12.0.0 |
| (Semigroup a, Semigroup b) => Semigroup (a, b) | Since: base-4.9.0.0 |
| Semigroup b => Semigroup (a -> b) | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Const a b) | Since: base-4.9.0.0 |
| Semigroup (f p) => Semigroup (Rec1 f p) | Since: base-4.12.0.0 |
| (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | Since: base-4.9.0.0 |
| (Semigroup (f a), Semigroup (g a)) => Semigroup (Product f g a) | Since: base-4.16.0.0 |
| (Semigroup (f p), Semigroup (g p)) => Semigroup ((f :*: g) p) | Since: base-4.12.0.0 |
| Semigroup c => Semigroup (K1 i c p) | Since: base-4.12.0.0 |
| (Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) | Since: base-4.9.0.0 |
| Semigroup (f (g a)) => Semigroup (Compose f g a) | Since: base-4.16.0.0 |
| Semigroup (f (g p)) => Semigroup ((f :.: g) p) | Since: base-4.12.0.0 |
| Semigroup (f p) => Semigroup (M1 i c f p) | Since: base-4.12.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 (Functor t, Foldable t) => Traversable (t :: Type -> Type) where #
Functors representing data structures that can be transformed to
structures of the same shape by performing an Applicative (or,
therefore, Monad) action on each element from left to right.
A more detailed description of what same shape means, the various methods, how traversals are constructed, and example advanced use-cases can be found in the Overview section of Data.Traversable.
For the class laws see the Laws section of Data.Traversable.
Methods
traverse :: Applicative f => (a -> f b) -> t a -> f (t b) #
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_.
Examples
Basic usage:
In the first two examples we show each evaluated action mapping to the output structure.
>>>traverse Just [1,2,3,4]Just [1,2,3,4]
>>>traverse id [Right 1, Right 2, Right 3, Right 4]Right [1,2,3,4]
In the next examples, we show that Nothing and Left values short
circuit the created structure.
>>>traverse (const Nothing) [1,2,3,4]Nothing
>>>traverse (\x -> if odd x then Just x else Nothing) [1,2,3,4]Nothing
>>>traverse id [Right 1, Right 2, Right 3, Right 4, Left 0]Left 0
sequenceA :: Applicative f => t (f a) -> f (t a) #
Evaluate each action in the structure from left to right, and
collect the results. For a version that ignores the results
see sequenceA_.
Examples
Basic usage:
For the first two examples we show sequenceA fully evaluating a a structure and collecting the results.
>>>sequenceA [Just 1, Just 2, Just 3]Just [1,2,3]
>>>sequenceA [Right 1, Right 2, Right 3]Right [1,2,3]
The next two example show Nothing and Just will short circuit
the resulting structure if present in the input. For more context,
check the Traversable instances for Either and Maybe.
>>>sequenceA [Just 1, Just 2, Just 3, Nothing]Nothing
>>>sequenceA [Right 1, Right 2, Right 3, Left 4]Left 4
mapM :: Monad m => (a -> m b) -> t a -> m (t b) #
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_.
Examples
sequence :: Monad m => t (m a) -> m (t a) #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_.
Examples
Basic usage:
The first two examples are instances where the input and
and output of sequence are isomorphic.
>>>sequence $ Right [1,2,3,4][Right 1,Right 2,Right 3,Right 4]
>>>sequence $ [Right 1,Right 2,Right 3,Right 4]Right [1,2,3,4]
The following examples demonstrate short circuit behavior
for sequence.
>>>sequence $ Left [1,2,3,4]Left [1,2,3,4]
>>>sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]Left 0
Instances
| Traversable Complex | Since: base-4.9.0.0 |
| Traversable First | Since: base-4.9.0.0 |
| Traversable Last | Since: base-4.9.0.0 |
| Traversable Max | Since: base-4.9.0.0 |
| Traversable Min | Since: base-4.9.0.0 |
| Traversable SCC | Since: containers-0.5.9 |
| Traversable IntMap | Traverses in order of increasing key. |
| Traversable Digit | |
| Traversable Elem | |
| Traversable FingerTree | |
Defined in Data.Sequence.Internal Methods traverse :: Applicative f => (a -> f b) -> FingerTree a -> f (FingerTree b) # sequenceA :: Applicative f => FingerTree (f a) -> f (FingerTree a) # mapM :: Monad m => (a -> m b) -> FingerTree a -> m (FingerTree b) # sequence :: Monad m => FingerTree (m a) -> m (FingerTree a) # | |
| Traversable Node | |
| Traversable Seq | |
| Traversable ViewL | |
| Traversable ViewR | |
| Traversable Tree | |
| Traversable NonEmpty | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable Identity | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable First | Since: base-4.8.0.0 |
| Traversable Last | Since: base-4.8.0.0 |
| Traversable Down | Since: base-4.12.0.0 |
| Traversable Dual | Since: base-4.8.0.0 |
| Traversable Product | Since: base-4.8.0.0 |
| Traversable Sum | Since: base-4.8.0.0 |
| Traversable ZipList | Since: base-4.9.0.0 |
| Traversable Par1 | Since: base-4.9.0.0 |
| Traversable Maybe | Since: base-2.1 |
| Traversable Solo | Since: base-4.15 |
| Traversable [] | Since: base-2.1 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable (Arg a) | Since: base-4.9.0.0 |
| Traversable (Map k) | Traverses in order of increasing key. |
| Ix i => Traversable (Array i) | Since: base-2.1 |
| Traversable (Either a) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
| Traversable (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable (UAddr :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable (UChar :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable (UDouble :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable (UFloat :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable (UInt :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable (UWord :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable (V1 :: Type -> Type) | Since: base-4.9.0.0 |
| Traversable ((,) a) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable f => Traversable (Ap f) | Since: base-4.12.0.0 |
| Traversable f => Traversable (Alt f) | Since: base-4.12.0.0 |
| Traversable f => Traversable (Rec1 f) | Since: base-4.9.0.0 |
| (Traversable f, Traversable g) => Traversable (Product f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Product | |
| (Traversable f, Traversable g) => Traversable (Sum f g) | Since: base-4.9.0.0 |
| (Traversable f, Traversable g) => Traversable (f :*: g) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| (Traversable f, Traversable g) => Traversable (f :+: g) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable (K1 i c :: Type -> Type) | Since: base-4.9.0.0 |
| (Traversable f, Traversable g) => Traversable (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
| (Traversable f, Traversable g) => Traversable (f :.: g) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Traversable | |
| Traversable f => Traversable (M1 i c f) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Traversable | |
for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) #
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #
mapAccumL :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b) #
The mapAccumL function behaves like a combination of fmap
and foldl; it applies a function to each element of a structure,
passing an accumulating parameter from left to right, and returning
a final value of this accumulator together with the new structure.
Examples
Basic usage:
>>>mapAccumL (\a b -> (a + b, a)) 0 [1..10](55,[0,1,3,6,10,15,21,28,36,45])
>>>mapAccumL (\a b -> (a <> show b, a)) "0" [1..5]("012345",["0","01","012","0123","01234"])
mapAccumR :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b) #
The mapAccumR function behaves like a combination of fmap
and foldr; it applies a function to each element of a structure,
passing an accumulating parameter from right to left, and returning
a final value of this accumulator together with the new structure.
Examples
Basic usage:
>>>mapAccumR (\a b -> (a + b, a)) 0 [1..10](55,[54,52,49,45,40,34,27,19,10,0])
>>>mapAccumR (\a b -> (a <> show b, a)) "0" [1..5]("054321",["05432","0543","054","05","0"])
curry :: ((a, b) -> c) -> a -> b -> c #
Convert an uncurried function to a curried function.
Examples
>>>curry fst 1 21
uncurry :: (a -> b -> c) -> (a, b) -> c #
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]
The class Typeable allows a concrete representation of a type to
be calculated.
Minimal complete definition
typeRep#
class a ~# b => (a :: k) ~ (b :: k) infix 4 #
Lifted, homogeneous equality. By lifted, we mean that it
can be bogus (deferred type error). By homogeneous, the two
types a and b must have the same kinds.
Uninhabited data type
Since: base-4.8.0.0
Instances
| Semigroup Void | Since: base-4.9.0.0 |
| Exception Void | Since: base-4.8.0.0 |
Defined in GHC.Internal.Exception.Type Methods toException :: Void -> SomeException # fromException :: SomeException -> Maybe Void # displayException :: Void -> String # backtraceDesired :: Void -> Bool # | |
| Generic Void | |
| Read Void | Reading a Since: base-4.8.0.0 |
| Show Void | Since: base-4.8.0.0 |
| Eq Void | Since: base-4.8.0.0 |
| Ord Void | Since: base-4.8.0.0 |
| type Rep Void | Since: base-4.8.0.0 |
8-bit unsigned integer type
Instances
| PrintfArg Word8 | Since: base-2.1 |
Defined in Text.Printf | |
| Default Word8 | |
Defined in Data.Default.Internal | |
| Bits Word8 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods (.&.) :: Word8 -> Word8 -> Word8 # (.|.) :: Word8 -> Word8 -> Word8 # xor :: Word8 -> Word8 -> Word8 # complement :: Word8 -> Word8 # shift :: Word8 -> Int -> Word8 # rotate :: Word8 -> Int -> Word8 # setBit :: Word8 -> Int -> Word8 # clearBit :: Word8 -> Int -> Word8 # complementBit :: Word8 -> Int -> Word8 # testBit :: Word8 -> Int -> Bool # bitSizeMaybe :: Word8 -> Maybe Int # shiftL :: Word8 -> Int -> Word8 # unsafeShiftL :: Word8 -> Int -> Word8 # shiftR :: Word8 -> Int -> Word8 # unsafeShiftR :: Word8 -> Int -> Word8 # rotateL :: Word8 -> Int -> Word8 # | |
| FiniteBits Word8 | Since: base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word8 -> Int # countLeadingZeros :: Word8 -> Int # countTrailingZeros :: Word8 -> Int # | |
| Bounded Word8 | Since: base-2.1 |
| Enum Word8 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Ix Word8 | Since: base-2.1 |
| Num Word8 | Since: base-2.1 |
| Read Word8 | Since: base-2.1 |
| Integral Word8 | Since: base-2.1 |
| Real Word8 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word8 -> Rational # | |
| Show Word8 | Since: base-2.1 |
| Eq Word8 | Since: base-2.1 |
| Ord Word8 | Since: base-2.1 |
Instances
| PrintfArg Word | Since: base-2.1 | ||||
Defined in Text.Printf | |||||
| Default Word | |||||
Defined in Data.Default.Internal | |||||
| Bits Word | Since: base-2.1 | ||||
Defined in GHC.Internal.Bits Methods (.&.) :: Word -> Word -> Word # (.|.) :: Word -> Word -> Word # complement :: Word -> Word # shift :: Word -> Int -> Word # rotate :: Word -> Int -> Word # setBit :: Word -> Int -> Word # clearBit :: Word -> Int -> Word # complementBit :: Word -> Int -> Word # testBit :: Word -> Int -> Bool # bitSizeMaybe :: Word -> Maybe Int # shiftL :: Word -> Int -> Word # unsafeShiftL :: Word -> Int -> Word # shiftR :: Word -> Int -> Word # unsafeShiftR :: Word -> Int -> Word # rotateL :: Word -> Int -> Word # | |||||
| FiniteBits Word | Since: base-4.6.0.0 | ||||
Defined in GHC.Internal.Bits Methods finiteBitSize :: Word -> Int # countLeadingZeros :: Word -> Int # countTrailingZeros :: Word -> Int # | |||||
| Bounded Word | Since: base-2.1 | ||||
| Enum Word | Since: base-2.1 | ||||
| Num Word | Since: base-2.1 | ||||
| Read Word | Since: base-4.5.0.0 | ||||
| Integral Word | Since: base-2.1 | ||||
| Real Word | Since: base-2.1 | ||||
Defined in GHC.Internal.Real Methods toRational :: Word -> Rational # | |||||
| Show Word | Since: base-2.1 | ||||
| Eq Word | |||||
| Ord Word | |||||
| Generic1 (URec Word :: k -> Type) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Foldable (UWord :: Type -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => UWord m -> m # foldMap :: Monoid m => (a -> m) -> UWord a -> m # foldMap' :: Monoid m => (a -> m) -> UWord a -> m # foldr :: (a -> b -> b) -> b -> UWord a -> b # foldr' :: (a -> b -> b) -> b -> UWord a -> b # foldl :: (b -> a -> b) -> b -> UWord a -> b # foldl' :: (b -> a -> b) -> b -> UWord a -> b # foldr1 :: (a -> a -> a) -> UWord a -> a # foldl1 :: (a -> a -> a) -> UWord a -> a # elem :: Eq a => a -> UWord a -> Bool # maximum :: Ord a => UWord a -> a # minimum :: Ord a => UWord a -> a # | |||||
| Traversable (UWord :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Functor (URec Word :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Generic (URec Word p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Show (URec Word p) | Since: base-4.9.0.0 | ||||
| Eq (URec Word p) | Since: base-4.9.0.0 | ||||
| Ord (URec Word p) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| data URec Word (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 | ||||
| type Rep1 (URec Word :: k -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| type Rep (URec Word p) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
64-bit unsigned integer type
Instances
| PrintfArg Word64 | Since: base-2.1 |
Defined in Text.Printf | |
| Default Word64 | |
Defined in Data.Default.Internal | |
| Bits Word64 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods (.&.) :: Word64 -> Word64 -> Word64 # (.|.) :: Word64 -> Word64 -> Word64 # xor :: Word64 -> Word64 -> Word64 # complement :: Word64 -> Word64 # shift :: Word64 -> Int -> Word64 # rotate :: Word64 -> Int -> Word64 # setBit :: Word64 -> Int -> Word64 # clearBit :: Word64 -> Int -> Word64 # complementBit :: Word64 -> Int -> Word64 # testBit :: Word64 -> Int -> Bool # bitSizeMaybe :: Word64 -> Maybe Int # shiftL :: Word64 -> Int -> Word64 # unsafeShiftL :: Word64 -> Int -> Word64 # shiftR :: Word64 -> Int -> Word64 # unsafeShiftR :: Word64 -> Int -> Word64 # rotateL :: Word64 -> Int -> Word64 # | |
| FiniteBits Word64 | Since: base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word64 -> Int # countLeadingZeros :: Word64 -> Int # countTrailingZeros :: Word64 -> Int # | |
| Bounded Word64 | Since: base-2.1 |
| Enum Word64 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Ix Word64 | Since: base-2.1 |
| Num Word64 | Since: base-2.1 |
| Read Word64 | Since: base-2.1 |
| Integral Word64 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Real Word64 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word64 -> Rational # | |
| Show Word64 | Since: base-2.1 |
| Eq Word64 | Since: base-2.1 |
| Ord Word64 | Since: base-2.1 |
32-bit unsigned integer type
Instances
| PrintfArg Word32 | Since: base-2.1 |
Defined in Text.Printf | |
| Default Word32 | |
Defined in Data.Default.Internal | |
| Bits Word32 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods (.&.) :: Word32 -> Word32 -> Word32 # (.|.) :: Word32 -> Word32 -> Word32 # xor :: Word32 -> Word32 -> Word32 # complement :: Word32 -> Word32 # shift :: Word32 -> Int -> Word32 # rotate :: Word32 -> Int -> Word32 # setBit :: Word32 -> Int -> Word32 # clearBit :: Word32 -> Int -> Word32 # complementBit :: Word32 -> Int -> Word32 # testBit :: Word32 -> Int -> Bool # bitSizeMaybe :: Word32 -> Maybe Int # shiftL :: Word32 -> Int -> Word32 # unsafeShiftL :: Word32 -> Int -> Word32 # shiftR :: Word32 -> Int -> Word32 # unsafeShiftR :: Word32 -> Int -> Word32 # rotateL :: Word32 -> Int -> Word32 # | |
| FiniteBits Word32 | Since: base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word32 -> Int # countLeadingZeros :: Word32 -> Int # countTrailingZeros :: Word32 -> Int # | |
| Bounded Word32 | Since: base-2.1 |
| Enum Word32 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Ix Word32 | Since: base-2.1 |
| Num Word32 | Since: base-2.1 |
| Read Word32 | Since: base-2.1 |
| Integral Word32 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Real Word32 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word32 -> Rational # | |
| Show Word32 | Since: base-2.1 |
| Eq Word32 | Since: base-2.1 |
| Ord Word32 | Since: base-2.1 |
16-bit unsigned integer type
Instances
| PrintfArg Word16 | Since: base-2.1 |
Defined in Text.Printf | |
| Default Word16 | |
Defined in Data.Default.Internal | |
| Bits Word16 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods (.&.) :: Word16 -> Word16 -> Word16 # (.|.) :: Word16 -> Word16 -> Word16 # xor :: Word16 -> Word16 -> Word16 # complement :: Word16 -> Word16 # shift :: Word16 -> Int -> Word16 # rotate :: Word16 -> Int -> Word16 # setBit :: Word16 -> Int -> Word16 # clearBit :: Word16 -> Int -> Word16 # complementBit :: Word16 -> Int -> Word16 # testBit :: Word16 -> Int -> Bool # bitSizeMaybe :: Word16 -> Maybe Int # shiftL :: Word16 -> Int -> Word16 # unsafeShiftL :: Word16 -> Int -> Word16 # shiftR :: Word16 -> Int -> Word16 # unsafeShiftR :: Word16 -> Int -> Word16 # rotateL :: Word16 -> Int -> Word16 # | |
| FiniteBits Word16 | Since: base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word16 -> Int # countLeadingZeros :: Word16 -> Int # countTrailingZeros :: Word16 -> Int # | |
| Bounded Word16 | Since: base-2.1 |
| Enum Word16 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Ix Word16 | Since: base-2.1 |
| Num Word16 | Since: base-2.1 |
| Read Word16 | Since: base-2.1 |
| Integral Word16 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Real Word16 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word16 -> Rational # | |
| Show Word16 | Since: base-2.1 |
| Eq Word16 | Since: base-2.1 |
| Ord Word16 | Since: base-2.1 |
The value of is bottom if seq a ba 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 does
not guarantee that seq a ba 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 #
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.
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
Successor of a value. For numeric types, succ adds 1.
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..] with [n..] = enumFrom n,
a possible implementation being enumFrom n = n : enumFrom (succ n).
Examples
enumFrom 4 :: [Integer] = [4,5,6,7,...]
enumFrom 6 :: [Int] = [6,7,8,9,...,maxBound :: Int]
enumFromThen :: a -> a -> [a] #
Used in Haskell's translation of [n,n'..]
with [n,n'..] = enumFromThen n n', a possible implementation being
enumFromThen n n' = n : n' : worker (f x) (f x n'),
worker s v = v : worker s (s v), x = fromEnum n' - fromEnum n and
f n y
| n > 0 = f (n - 1) (succ y)
| n < 0 = f (n + 1) (pred y)
| otherwise = y
Examples
enumFromThen 4 6 :: [Integer] = [4,6,8,10...]
enumFromThen 6 2 :: [Int] = [6,2,-2,-6,...,minBound :: Int]
enumFromTo :: a -> a -> [a] #
Used in Haskell's translation of [n..m] with
[n..m] = enumFromTo n m, a possible implementation being
enumFromTo n m
| n <= m = n : enumFromTo (succ n) m
| otherwise = []
Examples
enumFromTo 6 10 :: [Int] = [6,7,8,9,10]
enumFromTo 42 1 :: [Integer] = []
enumFromThenTo :: a -> a -> a -> [a] #
Used in Haskell's translation of [n,n'..m] with
[n,n'..m] = enumFromThenTo n n' m, a possible implementation
being enumFromThenTo n n' m = worker (f x) (c x) n m,
x = fromEnum n' - fromEnum n, c x = bool (>=) ((x 0)
f n y
| n > 0 = f (n - 1) (succ y)
| n < 0 = f (n + 1) (pred y)
| otherwise = y
and
worker s c v m
| c v m = v : worker s c (s v) m
| otherwise = []
Examples
enumFromThenTo 4 2 -6 :: [Integer] = [4,2,0,-2,-4,-6]
enumFromThenTo 6 8 2 :: [Int] = []
Instances
| Enum Associativity | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods succ :: Associativity -> Associativity # pred :: Associativity -> Associativity # toEnum :: Int -> Associativity # fromEnum :: Associativity -> Int # enumFrom :: Associativity -> [Associativity] # enumFromThen :: Associativity -> Associativity -> [Associativity] # enumFromTo :: Associativity -> Associativity -> [Associativity] # enumFromThenTo :: Associativity -> Associativity -> Associativity -> [Associativity] # | |
| Enum DecidedStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods succ :: DecidedStrictness -> DecidedStrictness # pred :: DecidedStrictness -> DecidedStrictness # toEnum :: Int -> DecidedStrictness # fromEnum :: DecidedStrictness -> Int # enumFrom :: DecidedStrictness -> [DecidedStrictness] # enumFromThen :: DecidedStrictness -> DecidedStrictness -> [DecidedStrictness] # enumFromTo :: DecidedStrictness -> DecidedStrictness -> [DecidedStrictness] # enumFromThenTo :: DecidedStrictness -> DecidedStrictness -> DecidedStrictness -> [DecidedStrictness] # | |
| Enum SourceStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods succ :: SourceStrictness -> SourceStrictness # pred :: SourceStrictness -> SourceStrictness # toEnum :: Int -> SourceStrictness # fromEnum :: SourceStrictness -> Int # enumFrom :: SourceStrictness -> [SourceStrictness] # enumFromThen :: SourceStrictness -> SourceStrictness -> [SourceStrictness] # enumFromTo :: SourceStrictness -> SourceStrictness -> [SourceStrictness] # enumFromThenTo :: SourceStrictness -> SourceStrictness -> SourceStrictness -> [SourceStrictness] # | |
| Enum SourceUnpackedness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods succ :: SourceUnpackedness -> SourceUnpackedness # pred :: SourceUnpackedness -> SourceUnpackedness # toEnum :: Int -> SourceUnpackedness # fromEnum :: SourceUnpackedness -> Int # enumFrom :: SourceUnpackedness -> [SourceUnpackedness] # enumFromThen :: SourceUnpackedness -> SourceUnpackedness -> [SourceUnpackedness] # enumFromTo :: SourceUnpackedness -> SourceUnpackedness -> [SourceUnpackedness] # enumFromThenTo :: SourceUnpackedness -> SourceUnpackedness -> SourceUnpackedness -> [SourceUnpackedness] # | |
| Enum Int16 | Since: base-2.1 |
Defined in GHC.Internal.Int | |
| Enum Int32 | Since: base-2.1 |
Defined in GHC.Internal.Int | |
| Enum Int64 | Since: base-2.1 |
Defined in GHC.Internal.Int | |
| Enum Int8 | Since: base-2.1 |
| Enum Word16 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Enum Word32 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Enum Word64 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Enum Word8 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Enum Ordering | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| Enum I8 | |
| Enum FPFormat | |
Defined in Data.Text.Lazy.Builder.RealFloat | |
| Enum Integer | Since: base-2.1 |
| Enum Natural | Since: base-4.8.0.0 |
| Enum () | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| Enum Bool | Since: base-2.1 |
| Enum Char | Since: base-2.1 |
| Enum Double |
List generators have extremely peculiar behavior, mandated by Haskell Report 2010:
Since: base-2.1 |
Defined in GHC.Internal.Float | |
| Enum Float |
List generators have extremely peculiar behavior, mandated by Haskell Report 2010:
Since: base-2.1 |
Defined in GHC.Internal.Float | |
| Enum Int | Since: base-2.1 |
| Enum Levity | Since: base-4.16.0.0 |
Defined in GHC.Internal.Enum | |
| Enum VecCount | Since: base-4.10.0.0 |
Defined in GHC.Internal.Enum | |
| Enum VecElem | Since: base-4.10.0.0 |
| Enum Word | Since: base-2.1 |
| Enum a => Enum (First a) | Since: base-4.9.0.0 |
| Enum a => Enum (Last a) | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| Enum a => Enum (Max a) | Since: base-4.9.0.0 |
| Enum a => Enum (Min a) | Since: base-4.9.0.0 |
| Enum a => Enum (WrappedMonoid a) | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods succ :: WrappedMonoid a -> WrappedMonoid a # pred :: WrappedMonoid a -> WrappedMonoid a # toEnum :: Int -> WrappedMonoid a # fromEnum :: WrappedMonoid a -> Int # enumFrom :: WrappedMonoid a -> [WrappedMonoid a] # enumFromThen :: WrappedMonoid a -> WrappedMonoid a -> [WrappedMonoid a] # enumFromTo :: WrappedMonoid a -> WrappedMonoid a -> [WrappedMonoid a] # enumFromThenTo :: WrappedMonoid a -> WrappedMonoid a -> WrappedMonoid a -> [WrappedMonoid a] # | |
| Enum a => Enum (Identity a) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity Methods succ :: Identity a -> Identity a # pred :: Identity a -> Identity a # fromEnum :: Identity a -> Int # enumFrom :: Identity a -> [Identity a] # enumFromThen :: Identity a -> Identity a -> [Identity a] # enumFromTo :: Identity a -> Identity a -> [Identity a] # enumFromThenTo :: Identity a -> Identity a -> Identity a -> [Identity a] # | |
| (Enum a, Bounded a, Eq a) => Enum (Down a) | Swaps Since: base-4.18.0.0 |
Defined in GHC.Internal.Data.Ord | |
| Integral a => Enum (Ratio a) | Since: base-2.0.1 |
| Enum a => Enum (Solo a) | |
Defined in GHC.Internal.Enum | |
| Enum (Fixed a) | Recall that, for numeric types,
and likewise
In other words,
and similarly
This is worth bearing in mind when defining [1..10] :: [Pico] evaluates to However, this is not true. On the contrary, similarly to the above
implementations of [1.000000000000, 1.00000000001, 1.00000000002, ..., 10.000000000000] and contains Since: base-2.1 |
| Enum (Proxy s) | Since: base-4.7.0.0 |
| Enum a => Enum (Const a b) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const Methods succ :: Const a b -> Const a b # pred :: Const a b -> Const a b # fromEnum :: Const a b -> Int # enumFrom :: Const a b -> [Const a b] # enumFromThen :: Const a b -> Const a b -> [Const a b] # enumFromTo :: Const a b -> Const a b -> [Const a b] # enumFromThenTo :: Const a b -> Const a b -> Const a b -> [Const a b] # | |
| a ~ b => Enum (a :~: b) | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Type.Equality Methods succ :: (a :~: b) -> a :~: b # pred :: (a :~: b) -> a :~: b # fromEnum :: (a :~: b) -> Int # enumFrom :: (a :~: b) -> [a :~: b] # enumFromThen :: (a :~: b) -> (a :~: b) -> [a :~: b] # enumFromTo :: (a :~: b) -> (a :~: b) -> [a :~: b] # enumFromThenTo :: (a :~: b) -> (a :~: b) -> (a :~: b) -> [a :~: b] # | |
| a ~~ b => Enum (a :~~: b) | Since: base-4.10.0.0 |
Defined in GHC.Internal.Data.Type.Equality Methods succ :: (a :~~: b) -> a :~~: b # pred :: (a :~~: b) -> a :~~: b # fromEnum :: (a :~~: b) -> Int # enumFrom :: (a :~~: b) -> [a :~~: b] # enumFromThen :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromTo :: (a :~~: b) -> (a :~~: b) -> [a :~~: b] # enumFromThenTo :: (a :~~: b) -> (a :~~: b) -> (a :~~: b) -> [a :~~: b] # | |
| Enum (f (g a)) => Enum (Compose f g a) | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods succ :: Compose f g a -> Compose f g a # pred :: Compose f g a -> Compose f g a # toEnum :: Int -> Compose f g a # fromEnum :: Compose f g a -> Int # enumFrom :: Compose f g a -> [Compose f g a] # enumFromThen :: Compose f g a -> Compose f g a -> [Compose f g a] # enumFromTo :: Compose f g a -> Compose f g a -> [Compose f g a] # enumFromThenTo :: Compose f g a -> Compose f g a -> Compose f g a -> [Compose f g a] # | |
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
| Bounded Associativity | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
| Bounded DecidedStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
| Bounded SourceStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
| Bounded SourceUnpackedness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics | |
| Bounded Int16 | Since: base-2.1 |
| Bounded Int32 | Since: base-2.1 |
| Bounded Int64 | Since: base-2.1 |
| Bounded Int8 | Since: base-2.1 |
| Bounded Word16 | Since: base-2.1 |
| Bounded Word32 | Since: base-2.1 |
| Bounded Word64 | Since: base-2.1 |
| Bounded Word8 | Since: base-2.1 |
| Bounded Ordering | Since: base-2.1 |
| Bounded I8 | |
| Bounded FPFormat | |
| Bounded () | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| Bounded Bool | Since: base-2.1 |
| Bounded Char | Since: base-2.1 |
| Bounded Int | Since: base-2.1 |
| Bounded Levity | Since: base-4.16.0.0 |
| Bounded VecCount | Since: base-4.10.0.0 |
| Bounded VecElem | Since: base-4.10.0.0 |
| Bounded Word | Since: base-2.1 |
| Bounded a => Bounded (First a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Last a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Max a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Min a) | Since: base-4.9.0.0 |
| Bounded m => Bounded (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup | |
| Bounded a => Bounded (Identity a) | Since: base-4.9.0.0 |
| Bounded a => Bounded (Down a) | Swaps Since: base-4.14.0.0 |
| Bounded a => Bounded (Solo a) | |
| Bounded (Proxy t) | Since: base-4.7.0.0 |
| (Bounded a, Bounded b) => Bounded (a, b) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| Bounded a => Bounded (Const a b) | Since: base-4.9.0.0 |
| a ~ b => Bounded (a :~: b) | Since: base-4.7.0.0 |
| (Bounded a, Bounded b, Bounded c) => Bounded (a, b, c) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| a ~~ b => Bounded (a :~~: b) | Since: base-4.10.0.0 |
| (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a, b, c, d) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| Bounded (f (g a)) => Bounded (Compose f g a) | Since: base-4.19.0.0 |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a, b, c, d, e) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded (a, b, c, d, e, f) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g) => Bounded (a, b, c, d, e, f, g) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h) => Bounded (a, b, c, d, e, f, g, h) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i) => Bounded (a, b, c, d, e, f, g, h, i) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j) => Bounded (a, b, c, d, e, f, g, h, i, j) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k) => Bounded (a, b, c, d, e, f, g, h, i, j, k) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
| (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | Since: base-2.1 |
Defined in GHC.Internal.Enum | |
error :: HasCallStack => [Char] -> a #
error stops execution and displays an error message.
undefined :: HasCallStack => a #
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
| PrintfArg Float | Since: base-2.1 | ||||
Defined in Text.Printf | |||||
| Default Float | |||||
Defined in Data.Default.Internal | |||||
| Enum Float |
List generators have extremely peculiar behavior, mandated by Haskell Report 2010:
Since: base-2.1 | ||||
Defined in GHC.Internal.Float | |||||
| Floating Float | Since: base-2.1 | ||||
| RealFloat Float | Since: base-2.1 | ||||
Defined in GHC.Internal.Float Methods floatRadix :: Float -> Integer # floatDigits :: Float -> Int # floatRange :: Float -> (Int, Int) # decodeFloat :: Float -> (Integer, Int) # encodeFloat :: Integer -> Int -> Float # significand :: Float -> Float # scaleFloat :: Int -> Float -> Float # isInfinite :: Float -> Bool # isDenormalized :: Float -> Bool # isNegativeZero :: Float -> Bool # | |||||
| Num Float | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:
Since: base-2.1 | ||||
| Read Float | Since: base-2.1 | ||||
| Fractional Float | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.
Since: base-2.1 | ||||
| Real Float | Beware that
Since: base-2.1 | ||||
Defined in GHC.Internal.Float Methods toRational :: Float -> Rational # | |||||
| RealFrac Float | Beware that results for non-finite arguments are garbage:
and get even more non-sensical if you ask for Since: base-2.1 | ||||
| Show Float | Since: base-2.1 | ||||
| Eq Float | Note that due to the presence of
Also note that
| ||||
| Ord Float | See | ||||
| Generic1 (URec Float :: k -> Type) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Foldable (UFloat :: Type -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => UFloat m -> m # foldMap :: Monoid m => (a -> m) -> UFloat a -> m # foldMap' :: Monoid m => (a -> m) -> UFloat a -> m # foldr :: (a -> b -> b) -> b -> UFloat a -> b # foldr' :: (a -> b -> b) -> b -> UFloat a -> b # foldl :: (b -> a -> b) -> b -> UFloat a -> b # foldl' :: (b -> a -> b) -> b -> UFloat a -> b # foldr1 :: (a -> a -> a) -> UFloat a -> a # foldl1 :: (a -> a -> a) -> UFloat a -> a # elem :: Eq a => a -> UFloat a -> Bool # maximum :: Ord a => UFloat a -> a # minimum :: Ord a => UFloat a -> a # | |||||
| Traversable (UFloat :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Functor (URec Float :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Generic (URec Float p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Show (URec Float p) | |||||
| Eq (URec Float p) | |||||
| Ord (URec Float p) | |||||
Defined in GHC.Internal.Generics | |||||
| data URec Float (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 | ||||
| type Rep1 (URec Float :: k -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| type Rep (URec Float p) | |||||
Defined in GHC.Internal.Generics | |||||
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
| PrintfArg Double | Since: base-2.1 | ||||
Defined in Text.Printf | |||||
| Default Double | |||||
Defined in Data.Default.Internal | |||||
| Enum Double |
List generators have extremely peculiar behavior, mandated by Haskell Report 2010:
Since: base-2.1 | ||||
Defined in GHC.Internal.Float | |||||
| Floating Double | Since: base-2.1 | ||||
| RealFloat Double | Since: base-2.1 | ||||
Defined in GHC.Internal.Float Methods floatRadix :: Double -> Integer # floatDigits :: Double -> Int # floatRange :: Double -> (Int, Int) # decodeFloat :: Double -> (Integer, Int) # encodeFloat :: Integer -> Int -> Double # significand :: Double -> Double # scaleFloat :: Int -> Double -> Double # isInfinite :: Double -> Bool # isDenormalized :: Double -> Bool # isNegativeZero :: Double -> Bool # | |||||
| Num Double | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:
Since: base-2.1 | ||||
| Read Double | Since: base-2.1 | ||||
| Fractional Double | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.
Since: base-2.1 | ||||
| Real Double | Beware that
Since: base-2.1 | ||||
Defined in GHC.Internal.Float Methods toRational :: Double -> Rational # | |||||
| RealFrac Double | Beware that results for non-finite arguments are garbage:
and get even more non-sensical if you ask for Since: base-2.1 | ||||
| Show Double | Since: base-2.1 | ||||
| Eq Double | Note that due to the presence of
Also note that
| ||||
| Ord Double | IEEE 754 IEEE 754-2008, section 5.11 requires that if at least one of arguments of
IEEE 754-2008, section 5.10 defines Thus, users must be extremely cautious when using Moving further, the behaviour of IEEE 754-2008 compliant | ||||
| Generic1 (URec Double :: k -> Type) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Foldable (UDouble :: Type -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => UDouble m -> m # foldMap :: Monoid m => (a -> m) -> UDouble a -> m # foldMap' :: Monoid m => (a -> m) -> UDouble a -> m # foldr :: (a -> b -> b) -> b -> UDouble a -> b # foldr' :: (a -> b -> b) -> b -> UDouble a -> b # foldl :: (b -> a -> b) -> b -> UDouble a -> b # foldl' :: (b -> a -> b) -> b -> UDouble a -> b # foldr1 :: (a -> a -> a) -> UDouble a -> a # foldl1 :: (a -> a -> a) -> UDouble a -> a # elem :: Eq a => a -> UDouble a -> Bool # maximum :: Ord a => UDouble a -> a # minimum :: Ord a => UDouble a -> a # | |||||
| Traversable (UDouble :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Functor (URec Double :: Type -> Type) | Since: base-4.9.0.0 | ||||
| Generic (URec Double p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Show (URec Double p) | Since: base-4.9.0.0 | ||||
| Eq (URec Double p) | Since: base-4.9.0.0 | ||||
| Ord (URec Double p) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics Methods compare :: URec Double p -> URec Double p -> Ordering # (<) :: URec Double p -> URec Double p -> Bool # (<=) :: URec Double p -> URec Double p -> Bool # (>) :: URec Double p -> URec Double p -> Bool # (>=) :: URec Double p -> URec Double p -> Bool # | |||||
| data URec Double (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 | ||||
| type Rep1 (URec Double :: k -> Type) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| type Rep (URec Double p) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
Representable types of kind *.
This class is derivable in GHC with the DeriveGeneric flag on.
A Generic instance must satisfy the following laws:
from.to≡idto.from≡id
Instances
| Generic ShortByteString | |||||
Defined in Data.ByteString.Short.Internal Associated Types
Methods from :: ShortByteString -> Rep ShortByteString x # to :: Rep ShortByteString x -> ShortByteString # | |||||
| Generic Void | |||||
| Generic Fingerprint | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic Associativity | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic DecidedStrictness | |||||
Defined in GHC.Internal.Generics Associated Types
Methods from :: DecidedStrictness -> Rep DecidedStrictness x # to :: Rep DecidedStrictness x -> DecidedStrictness # | |||||
| Generic Fixity | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic SourceStrictness | |||||
Defined in GHC.Internal.Generics Associated Types
Methods from :: SourceStrictness -> Rep SourceStrictness x # to :: Rep SourceStrictness x -> SourceStrictness # | |||||
| Generic SourceUnpackedness | |||||
Defined in GHC.Internal.Generics Associated Types
Methods from :: SourceUnpackedness -> Rep SourceUnpackedness x # to :: Rep SourceUnpackedness x -> SourceUnpackedness # | |||||
| Generic SrcLoc | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic GeneralCategory | |||||
Defined in GHC.Internal.Generics Associated Types
Methods from :: GeneralCategory -> Rep GeneralCategory x # to :: Rep GeneralCategory x -> GeneralCategory # | |||||
| Generic Ordering | |||||
Defined in GHC.Internal.Generics | |||||
| Generic () | |||||
| Generic Bool | |||||
Defined in GHC.Internal.Generics | |||||
| Generic (Complex a) | |||||
Defined in Data.Complex Associated Types
| |||||
| Generic (First a) | |||||
Defined in Data.Semigroup Associated Types
| |||||
| Generic (Last a) | |||||
Defined in Data.Semigroup Associated Types
| |||||
| Generic (Max a) | |||||
Defined in Data.Semigroup Associated Types
| |||||
| Generic (Min a) | |||||
Defined in Data.Semigroup Associated Types
| |||||
| Generic (WrappedMonoid m) | |||||
Defined in Data.Semigroup Associated Types
Methods from :: WrappedMonoid m -> Rep (WrappedMonoid m) x # to :: Rep (WrappedMonoid m) x -> WrappedMonoid m # | |||||
| Generic (SCC vertex) | |||||
Defined in Data.Graph Associated Types
| |||||
| Generic (Digit a) | |||||
Defined in Data.Sequence.Internal Associated Types
| |||||
| Generic (Elem a) | |||||
Defined in Data.Sequence.Internal Associated Types
| |||||
| Generic (FingerTree a) | |||||
Defined in Data.Sequence.Internal Associated Types
| |||||
| Generic (Node a) | |||||
Defined in Data.Sequence.Internal Associated Types
| |||||
| Generic (ViewL a) | |||||
Defined in Data.Sequence.Internal Associated Types
| |||||
| Generic (ViewR a) | |||||
Defined in Data.Sequence.Internal Associated Types
| |||||
| Generic (Tree a) | |||||
Defined in Data.Tree Associated Types
| |||||
| Generic (NonEmpty a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (Identity a) | |||||
Defined in GHC.Internal.Data.Functor.Identity Associated Types
| |||||
| Generic (Down a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (ZipList a) | |||||
Defined in GHC.Internal.Functor.ZipList Associated Types
| |||||
| Generic (Par1 p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (Maybe a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (Solo a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic [a] | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (WrappedMonad m a) | |||||
Defined in Control.Applicative Associated Types
Methods from :: WrappedMonad m a -> Rep (WrappedMonad m a) x # to :: Rep (WrappedMonad m a) x -> WrappedMonad m a # | |||||
| Generic (Arg a b) | |||||
Defined in Data.Semigroup Associated Types
| |||||
| Generic (Either a b) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (Proxy t) | |||||
Defined in GHC.Internal.Generics | |||||
| Generic (U1 p) | |||||
Defined in GHC.Internal.Generics | |||||
| Generic (V1 p) | |||||
| Generic (a, b) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (WrappedArrow a b c) | |||||
Defined in Control.Applicative Associated Types
Methods from :: WrappedArrow a b c -> Rep (WrappedArrow a b c) x # to :: Rep (WrappedArrow a b c) x -> WrappedArrow a b c # | |||||
| Generic (Kleisli m a b) | |||||
Defined in GHC.Internal.Control.Arrow Associated Types
| |||||
| Generic (Const a b) | |||||
Defined in GHC.Internal.Data.Functor.Const Associated Types
| |||||
| Generic (Rec1 f p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (URec (Ptr ()) p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (URec Char p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (URec Double p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (URec Float p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (URec Int p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (URec Word p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (Product f g a) | |||||
Defined in Data.Functor.Product Associated Types
| |||||
| Generic (Sum f g a) | |||||
Defined in Data.Functor.Sum Associated Types
| |||||
| Generic ((f :*: g) p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic ((f :+: g) p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (K1 i c p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (Compose f g a) | |||||
Defined in Data.Functor.Compose Associated Types
| |||||
| Generic ((f :.: g) p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (M1 i c f p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h, i) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h, i, j) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h, i, j, k) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h, i, j, k, l) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Generic (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Arbitrary precision integers. In contrast with fixed-size integral types
such as Int, the Integer type represents the entire infinite range of
integers.
Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.
If the value is small (i.e., fits into an Int), the IS constructor is
used. Otherwise IP and IN constructors are used to store a BigNat
representing the positive or the negative value magnitude, respectively.
Invariant: IP and IN are used iff the value does not fit in IS.
Instances
| PrintfArg Integer | Since: base-2.1 |
Defined in Text.Printf | |
| Default Integer | |
Defined in Data.Default.Internal | |
| Bits Integer | Since: base-2.1 |
Defined in GHC.Internal.Bits Methods (.&.) :: Integer -> Integer -> Integer # (.|.) :: Integer -> Integer -> Integer # xor :: Integer -> Integer -> Integer # complement :: Integer -> Integer # shift :: Integer -> Int -> Integer # rotate :: Integer -> Int -> Integer # setBit :: Integer -> Int -> Integer # clearBit :: Integer -> Int -> Integer # complementBit :: Integer -> Int -> Integer # testBit :: Integer -> Int -> Bool # bitSizeMaybe :: Integer -> Maybe Int # shiftL :: Integer -> Int -> Integer # unsafeShiftL :: Integer -> Int -> Integer # shiftR :: Integer -> Int -> Integer # unsafeShiftR :: Integer -> Int -> Integer # rotateL :: Integer -> Int -> Integer # | |
| Enum Integer | Since: base-2.1 |
| Num Integer | Since: base-2.1 |
| Read Integer | Since: base-2.1 |
| Integral Integer | Since: base-2.0.1 |
Defined in GHC.Internal.Real | |
| Real Integer | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Integer -> Rational # | |
| Show Integer | Since: base-2.1 |
| Eq Integer | |
| Ord Integer | |
Basic numeric class.
The Haskell Report defines no laws for Num. However, ( and +)( are
customarily expected to define a ring and have the following properties:*)
- Associativity of
(+) (x + y) + z=x + (y + z)- Commutativity of
(+) x + y=y + xis the additive identityfromInteger0x + fromInteger 0=xnegategives the additive inversex + negate x=fromInteger 0- Associativity of
(*) (x * y) * z=x * (y * z)is the multiplicative identityfromInteger1x * fromInteger 1=xandfromInteger 1 * x=x- Distributivity of
(with respect to*)(+) a * (b + c)=(a * b) + (a * c)and(b + c) * a=(b * a) + (c * a)- Coherence with
toInteger - if the type also implements
Integral, thenfromIntegeris a left inverse fortoInteger, i.e.fromInteger (toInteger i) == i
Note that it isn't customarily expected that a type instance of both Num
and Ord implement an ordered ring. Indeed, in base only Integer and
Rational do.
Methods
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 #
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
| Num Int16 | Since: base-2.1 |
| Num Int32 | Since: base-2.1 |
| Num Int64 | Since: base-2.1 |
| Num Int8 | Since: base-2.1 |
| Num Word16 | Since: base-2.1 |
| Num Word32 | Since: base-2.1 |
| Num Word64 | Since: base-2.1 |
| Num Word8 | Since: base-2.1 |
| Num I8 | |
| Num Size | |
| Num Integer | Since: base-2.1 |
| Num Natural | Note that Since: base-4.8.0.0 |
| Num Double | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:
Since: base-2.1 |
| Num Float | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:
Since: base-2.1 |
| Num Int | Since: base-2.1 |
| Num Word | Since: base-2.1 |
| RealFloat a => Num (Complex a) | Since: base-2.1 |
| Num a => Num (Max a) | Since: base-4.9.0.0 |
| Num a => Num (Min a) | Since: base-4.9.0.0 |
| Num a => Num (Identity a) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity | |
| Num a => Num (Down a) | Since: base-4.11.0.0 |
| Integral a => Num (Ratio a) | Since: base-2.0.1 |
| HasResolution a => Num (Fixed a) | Multiplication is not associative or distributive:
Since: base-2.1 |
| Num a => Num (Op a b) | |
| Num a => Num (Const a b) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const | |
| Num (f (g a)) => Num (Compose f g a) | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods (+) :: Compose f g a -> Compose f g a -> Compose f g a # (-) :: Compose f g a -> Compose f g a -> Compose f g a # (*) :: Compose f g a -> Compose f g a -> Compose f g a # negate :: Compose f g a -> Compose f g a # abs :: Compose f g a -> Compose f g a # signum :: Compose f g a -> Compose f g a # fromInteger :: Integer -> Compose f g a # | |
module GHC.OverloadedLabels
class Num a => Fractional a where #
Fractional numbers, supporting real division.
The Haskell Report defines no laws for Fractional. However, ( and
+)( are customarily expected to define a division ring and have the
following properties:*)
recipgives the multiplicative inversex * recip x=recip x * x=fromInteger 1- Totality of
toRational toRationalis total- Coherence with
toRational - if the type also implements
Real, thenfromRationalis a left inverse fortoRational, i.e.fromRational (toRational i) = i
Note that it isn't customarily expected that a type instance of
Fractional implement a field. However, all instances in base do.
Methods
fromRational :: Rational -> a #
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 | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.
Since: base-2.1 |
| Fractional Float | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.
Since: base-2.1 |
| RealFloat a => Fractional (Complex a) | Since: base-2.1 |
| Fractional a => Fractional (Identity a) | Since: base-4.9.0.0 |
| Fractional a => Fractional (Down a) | Since: base-4.14.0.0 |
| Integral a => Fractional (Ratio a) | Since: base-2.0.1 |
| HasResolution a => Fractional (Fixed a) | Since: base-2.1 |
| Fractional a => Fractional (Op a b) | |
| Fractional a => Fractional (Const a b) | Since: base-4.9.0.0 |
| Fractional (f (g a)) => Fractional (Compose f g a) | Since: base-4.20.0.0 |
fromIntegral :: (Integral a, Num b) => a -> b #
General coercion from Integral types.
WARNING: This function performs silent truncation if the result type is not at least as big as the argument's type.
realToFrac :: (Real a, Fractional b) => a -> b #
General coercion to Fractional types.
WARNING: This function goes through the Rational type, which does not have values for NaN for example.
This means it does not round-trip.
For Double it also behaves differently with or without -O0:
Prelude> realToFrac nan -- With -O0 -Infinity Prelude> realToFrac nan NaN
class (Real a, Enum a) => Integral a where #
Integral numbers, supporting integer division.
The Haskell Report defines no laws for Integral. However, Integral
instances are customarily expected to define a Euclidean domain and have the
following properties for the div/mod and quot/rem pairs, given
suitable Euclidean functions f and g:
x=y * quot x y + rem x ywithrem x y=fromInteger 0org (rem x y)<g yx=y * div x y + mod x ywithmod x y=fromInteger 0orf (mod x y)<f y
An example of a suitable Euclidean function, for Integer's instance, is
abs.
In addition, toInteger should be total, and fromInteger should be a left
inverse for it, i.e. fromInteger (toInteger i) = i.
Instances
| Integral Int16 | Since: base-2.1 |
| Integral Int32 | Since: base-2.1 |
| Integral Int64 | Since: base-2.1 |
| Integral Int8 | Since: base-2.1 |
| Integral Word16 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Integral Word32 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Integral Word64 | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Integral Word8 | Since: base-2.1 |
| Integral I8 | |
| Integral Integer | Since: base-2.0.1 |
Defined in GHC.Internal.Real | |
| Integral Natural | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real | |
| Integral Int | Since: base-2.0.1 |
| Integral Word | Since: base-2.1 |
| Integral a => Integral (Identity a) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity Methods quot :: Identity a -> Identity a -> Identity a # rem :: Identity a -> Identity a -> Identity a # div :: Identity a -> Identity a -> Identity a # mod :: Identity a -> Identity a -> Identity a # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) # divMod :: Identity a -> Identity a -> (Identity a, Identity a) # | |
| Integral a => Integral (Const a b) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const Methods quot :: Const a b -> Const a b -> Const a b # rem :: Const a b -> Const a b -> Const a b # div :: Const a b -> Const a b -> Const a b # mod :: Const a b -> Const a b -> Const a b # quotRem :: Const a b -> Const a b -> (Const a b, Const a b) # divMod :: Const a b -> Const a b -> (Const a b, Const a b) # | |
| Integral (f (g a)) => Integral (Compose f g a) | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods quot :: Compose f g a -> Compose f g a -> Compose f g a # rem :: Compose f g a -> Compose f g a -> Compose f g a # div :: Compose f g a -> Compose f g a -> Compose f g a # mod :: Compose f g a -> Compose f g a -> Compose f g a # quotRem :: Compose f g a -> Compose f g a -> (Compose f g a, Compose f g a) # divMod :: Compose f g a -> Compose f g a -> (Compose f g a, Compose f g a) # | |
class (Num a, Ord a) => Real a where #
Real numbers.
The Haskell report defines no laws for Real, however Real instances
are customarily expected to adhere to the following law:
- Coherence with
fromRational - if the type also implements
Fractional, thenfromRationalis a left inverse fortoRational, i.e.fromRational (toRational i) = i
The law does not hold for Float, Double, CFloat,
CDouble, etc., because these types contain non-finite values,
which cannot be roundtripped through Rational.
Instances
| Real Int16 | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int16 -> Rational # | |
| Real Int32 | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int32 -> Rational # | |
| Real Int64 | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int64 -> Rational # | |
| Real Int8 | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int8 -> Rational # | |
| Real Word16 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word16 -> Rational # | |
| Real Word32 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word32 -> Rational # | |
| Real Word64 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word64 -> Rational # | |
| Real Word8 | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word8 -> Rational # | |
| Real I8 | |
Defined in Data.Text.Foreign Methods toRational :: I8 -> Rational # | |
| Real Integer | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Integer -> Rational # | |
| Real Natural | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real Methods toRational :: Natural -> Rational # | |
| Real Double | Beware that
Since: base-2.1 |
Defined in GHC.Internal.Float Methods toRational :: Double -> Rational # | |
| Real Float | Beware that
Since: base-2.1 |
Defined in GHC.Internal.Float Methods toRational :: Float -> Rational # | |
| Real Int | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Int -> Rational # | |
| Real Word | Since: base-2.1 |
Defined in GHC.Internal.Real Methods toRational :: Word -> Rational # | |
| Real a => Real (Identity a) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity Methods toRational :: Identity a -> Rational # | |
| Real a => Real (Down a) | Since: base-4.14.0.0 |
Defined in GHC.Internal.Data.Ord Methods toRational :: Down a -> Rational # | |
| Integral a => Real (Ratio a) | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Ratio a -> Rational # | |
| HasResolution a => Real (Fixed a) | Since: base-2.1 |
Defined in Data.Fixed Methods toRational :: Fixed a -> Rational # | |
| Real a => Real (Const a b) | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const Methods toRational :: Const a b -> Rational # | |
| Real (f (g a)) => Real (Compose f g a) | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods toRational :: Compose f g a -> Rational # | |
class (Real a, Fractional a) => RealFrac a where #
Extracting components of fractions.
Minimal complete definition
Methods
properFraction :: Integral b => a -> (b, a) #
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 #
returns the integer nearest truncate xx between zero and x
round :: Integral b => a -> b #
returns the nearest integer to round xx;
the even integer if x is equidistant between two integers
ceiling :: Integral b => a -> b #
returns the least integer not less than ceiling xx
floor :: Integral b => a -> b #
returns the greatest integer not greater than floor xx
Instances
| RealFrac Double | Beware that results for non-finite arguments are garbage:
and get even more non-sensical if you ask for Since: base-2.1 |
| RealFrac Float | Beware that results for non-finite arguments are garbage:
and get even more non-sensical if you ask for Since: base-2.1 |
| RealFrac a => RealFrac (Identity a) | Since: base-4.9.0.0 |
| RealFrac a => RealFrac (Down a) | Since: base-4.14.0.0 |
| Integral a => RealFrac (Ratio a) | Since: base-2.0.1 |
| HasResolution a => RealFrac (Fixed a) | Since: base-2.1 |
| RealFrac a => RealFrac (Const a b) | Since: base-4.9.0.0 |
| RealFrac (f (g a)) => RealFrac (Compose f g a) | Since: base-4.20.0.0 |
Rational numbers, with numerator and denominator of some Integral type.
Note that Ratio's instances inherit the deficiencies from the type
parameter's. For example, Ratio Natural's Num instance has similar
problems to Natural's.
Instances
| Integral a => Default (Ratio a) | |
Defined in Data.Default.Internal | |
| Integral a => Enum (Ratio a) | Since: base-2.0.1 |
| Integral a => Num (Ratio a) | Since: base-2.0.1 |
| (Integral a, Read a) => Read (Ratio a) | Since: base-2.1 |
| Integral a => Fractional (Ratio a) | Since: base-2.0.1 |
| Integral a => Real (Ratio a) | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Ratio a -> Rational # | |
| Integral a => RealFrac (Ratio a) | Since: base-2.0.1 |
| Show a => Show (Ratio a) | Since: base-2.0.1 |
| Eq a => Eq (Ratio a) | Since: base-2.1 |
| Integral a => Ord (Ratio a) | Since: base-2.0.1 |
Extract the numerator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.
denominator :: Ratio a -> a #
Extract the denominator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 #
raise a number to an integral power
gcd :: Integral a => a -> a -> a #
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 #
is the smallest positive integer that both lcm x yx and y divide.
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)".
Instances
| Show ByteArray | Since: base-4.17.0.0 |
| Show Timeout | Since: base-4.0 |
| Show Builder | Since: bytestring-0.11.1.0 |
| Show FormatMode | |
| Show ByteString | |
Defined in Data.ByteString.Internal.Type Methods showsPrec :: Int -> ByteString -> ShowS # show :: ByteString -> String # showList :: [ByteString] -> ShowS # | |
| Show SizeOverflowException | |
Defined in Data.ByteString.Internal.Type Methods showsPrec :: Int -> SizeOverflowException -> ShowS # show :: SizeOverflowException -> String # showList :: [SizeOverflowException] -> ShowS # | |
| Show ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods showsPrec :: Int -> ByteString -> ShowS # show :: ByteString -> String # showList :: [ByteString] -> ShowS # | |
| Show ShortByteString | |
Defined in Data.ByteString.Short.Internal Methods showsPrec :: Int -> ShortByteString -> ShowS # show :: ShortByteString -> String # showList :: [ShortByteString] -> ShowS # | |
| Show IntSet | |
| Show BitQueue | |
| Show BitQueueB | |
| Show Void | Since: base-4.8.0.0 |
| Show SomeTypeRep | Since: base-4.10.0.0 |
Defined in GHC.Internal.Data.Typeable.Internal Methods showsPrec :: Int -> SomeTypeRep -> ShowS # show :: SomeTypeRep -> String # showList :: [SomeTypeRep] -> ShowS # | |
| Show ArithException | Since: base-4.0.0.0 |
Defined in GHC.Internal.Exception.Type Methods showsPrec :: Int -> ArithException -> ShowS # show :: ArithException -> String # showList :: [ArithException] -> ShowS # | |
| Show SomeException | Since: ghc-internal-3.0 |
Defined in GHC.Internal.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # | |
| Show Associativity | Since: base-4.6.0.0 |
Defined in GHC.Internal.Generics Methods showsPrec :: Int -> Associativity -> ShowS # show :: Associativity -> String # showList :: [Associativity] -> ShowS # | |
| Show DecidedStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods showsPrec :: Int -> DecidedStrictness -> ShowS # show :: DecidedStrictness -> String # showList :: [DecidedStrictness] -> ShowS # | |
| Show Fixity | Since: base-4.6.0.0 |
| Show SourceStrictness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods showsPrec :: Int -> SourceStrictness -> ShowS # show :: SourceStrictness -> String # showList :: [SourceStrictness] -> ShowS # | |
| Show SourceUnpackedness | Since: base-4.9.0.0 |
Defined in GHC.Internal.Generics Methods showsPrec :: Int -> SourceUnpackedness -> ShowS # show :: SourceUnpackedness -> String # showList :: [SourceUnpackedness] -> ShowS # | |
| Show MaskingState | Since: base-4.3.0.0 |
Defined in GHC.Internal.IO Methods showsPrec :: Int -> MaskingState -> ShowS # show :: MaskingState -> String # showList :: [MaskingState] -> ShowS # | |
| Show Int16 | Since: base-2.1 |
| Show Int32 | Since: base-2.1 |
| Show Int64 | Since: base-2.1 |
| Show Int8 | Since: base-2.1 |
| Show FractionalExponentBase | |
Defined in GHC.Internal.Real Methods showsPrec :: Int -> FractionalExponentBase -> ShowS # show :: FractionalExponentBase -> String # showList :: [FractionalExponentBase] -> ShowS # | |
| Show CallStack | Since: base-4.9.0.0 |
| Show SrcLoc | Since: base-4.9.0.0 |
| Show SomeChar | |
| Show SomeSymbol | Since: base-4.7.0.0 |
Defined in GHC.Internal.TypeLits Methods showsPrec :: Int -> SomeSymbol -> ShowS # show :: SomeSymbol -> String # showList :: [SomeSymbol] -> ShowS # | |
| Show SomeNat | Since: base-4.7.0.0 |
| Show Word16 | Since: base-2.1 |
| Show Word32 | Since: base-2.1 |
| Show Word64 | Since: base-2.1 |
| Show Word8 | Since: base-2.1 |
| Show KindRep | |
| Show Module | Since: base-4.9.0.0 |
| Show Ordering | Since: base-2.1 |
| Show TrName | Since: base-4.9.0.0 |
| Show TyCon | Since: base-2.1 |
| Show TypeLitSort | Since: base-4.11.0.0 |
Defined in GHC.Internal.Show Methods showsPrec :: Int -> TypeLitSort -> ShowS # show :: TypeLitSort -> String # showList :: [TypeLitSort] -> ShowS # | |
| Show Decoding | |
| Show UnicodeException | |
Defined in Data.Text.Encoding.Error Methods showsPrec :: Int -> UnicodeException -> ShowS # show :: UnicodeException -> String # showList :: [UnicodeException] -> ShowS # | |
| Show I8 | |
| Show Text | |
| Show Builder | |
| Show PartialUtf8CodePoint | |
| Show Utf8State | |
| Show DecoderState | |
Defined in Data.Text.Internal.Encoding.Utf8 Methods showsPrec :: Int -> DecoderState -> ShowS # show :: DecoderState -> String # showList :: [DecoderState] -> ShowS # | |
| Show Size | |
| Show Text | |
| Show FPFormat | |
| Show Iter | |
| Show Integer | Since: base-2.1 |
| Show Natural | Since: base-4.8.0.0 |
| Show () | Since: base-2.1 |
| Show Bool | Since: base-2.1 |
| 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 Levity | Since: base-4.15.0.0 |
| Show RuntimeRep | Since: base-4.11.0.0 |
Defined in GHC.Internal.Show Methods showsPrec :: Int -> RuntimeRep -> ShowS # show :: RuntimeRep -> String # showList :: [RuntimeRep] -> ShowS # | |
| Show VecCount | Since: base-4.11.0.0 |
| Show VecElem | Since: base-4.11.0.0 |
| Show Word | Since: base-2.1 |
| Show a => Show (Complex a) | Since: base-2.1 |
| Show a => Show (First a) | Since: base-4.9.0.0 |
| Show a => Show (Last a) | Since: base-4.9.0.0 |
| Show a => Show (Max a) | Since: base-4.9.0.0 |
| Show a => Show (Min a) | Since: base-4.9.0.0 |
| Show m => Show (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods showsPrec :: Int -> WrappedMonoid m -> ShowS # show :: WrappedMonoid m -> String # showList :: [WrappedMonoid m] -> ShowS # | |
| Show vertex => Show (SCC vertex) | Since: containers-0.5.9 |
| Show a => Show (IntMap a) | |
| Show a => Show (Seq a) | |
| Show a => Show (ViewL a) | |
| Show a => Show (ViewR a) | |
| Show a => Show (Intersection a) | |
Defined in Data.Set.Internal Methods showsPrec :: Int -> Intersection a -> ShowS # show :: Intersection a -> String # showList :: [Intersection a] -> ShowS # | |
| Show a => Show (Set a) | |
| Show a => Show (Tree a) | |
| Show a => Show (NonEmpty a) | Since: base-4.11.0.0 |
| 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 (Down a) | This instance would be equivalent to the derived instances of the
Since: base-4.7.0.0 |
| Show a => Show (ExceptionWithContext a) | |
Defined in GHC.Internal.Exception.Type Methods showsPrec :: Int -> ExceptionWithContext a -> ShowS # show :: ExceptionWithContext a -> String # showList :: [ExceptionWithContext a] -> ShowS # | |
| Show e => Show (NoBacktrace e) | |
Defined in GHC.Internal.Exception.Type Methods showsPrec :: Int -> NoBacktrace e -> ShowS # show :: NoBacktrace e -> String # showList :: [NoBacktrace e] -> ShowS # | |
| Show a => Show (ZipList a) | Since: base-4.7.0.0 |
| Show p => Show (Par1 p) | Since: base-4.7.0.0 |
| Show a => Show (Ratio a) | Since: base-2.0.1 |
| Show (SChar c) | Since: base-4.18.0.0 |
| Show (SSymbol s) | Since: base-4.18.0.0 |
| Show (SNat n) | Since: base-4.18.0.0 |
| Show a => Show (Maybe a) | Since: base-2.1 |
| Show a => Show (Solo a) | Since: base-4.15 |
| Show a => Show [a] | Since: base-2.1 |
| HasResolution a => Show (Fixed a) | Since: base-2.1 |
| (Show a, Show b) => Show (Arg a b) | Since: base-4.9.0.0 |
| (Show k, Show a) => Show (Map k a) | |
| (Show a, Show b) => Show (Either a b) | Since: base-3.0 |
| Show (Proxy s) | Since: base-4.7.0.0 |
| Show (TypeRep a) | |
| Show (U1 p) | Since: base-4.9.0.0 |
| Show (V1 p) | Since: base-4.9.0.0 |
| (Show a, Show b) => Show (a, b) | Since: base-2.1 |
| Show a => Show (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Show (a :~: b) | Since: base-4.7.0.0 |
| Show (OrderingI a b) | |
| Show (f p) => Show (Rec1 f p) | Since: base-4.7.0.0 |
| Show (URec Char p) | Since: base-4.9.0.0 |
| Show (URec Double p) | Since: base-4.9.0.0 |
| Show (URec Float p) | |
| Show (URec Int p) | Since: base-4.9.0.0 |
| Show (URec Word p) | Since: base-4.9.0.0 |
| (Show a, Show b, Show c) => Show (a, b, c) | Since: base-2.1 |
| (Show (f a), Show (g a)) => Show (Product f g a) | Since: base-4.18.0.0 |
| (Show (f a), Show (g a)) => Show (Sum f g a) | Since: base-4.18.0.0 |
| Show (a :~~: b) | Since: base-4.10.0.0 |
| (Show (f p), Show (g p)) => Show ((f :*: g) p) | Since: base-4.7.0.0 |
| (Show (f p), Show (g p)) => Show ((f :+: g) p) | Since: base-4.7.0.0 |
| Show c => Show (K1 i c p) | Since: base-4.7.0.0 |
| (Show a, Show b, Show c, Show d) => Show (a, b, c, d) | Since: base-2.1 |
| Show (f (g a)) => Show (Compose f g a) | Since: base-4.18.0.0 |
| Show (f (g p)) => Show ((f :.: g) p) | Since: base-4.7.0.0 |
| Show (f p) => Show (M1 i c f p) | Since: base-4.7.0.0 |
| (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) | Since: base-2.1 |
| (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 |
type HasCallStack = ?callStack :: CallStack #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack is an
implementation detail and should not be considered part of the
CallStack API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
withFrozenCallStack :: HasCallStack => (HasCallStack => a) -> a #
Perform some computation without adding new entries to the CallStack.
Since: base-4.9.0.0
(Kind) This is the kind of type-level symbols.
Instances
| SingKind Symbol | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| TestCoercion SSymbol | Since: base-4.18.0.0 | ||||
Defined in GHC.Internal.TypeLits | |||||
| TestEquality SSymbol | Since: base-4.18.0.0 | ||||
Defined in GHC.Internal.TypeLits | |||||
| KnownSymbol a => SingI (a :: Symbol) | Since: base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics Methods sing :: Sing a | |||||
| type DemoteRep Symbol | |||||
Defined in GHC.Internal.Generics | |||||
| data Sing (s :: Symbol) | |||||
Defined in GHC.Internal.Generics | |||||
| type Compare (a :: Symbol) (b :: Symbol) | |||||
Defined in GHC.Internal.Data.Type.Ord | |||||
Natural number
Invariant: numbers <= 0xffffffffffffffff use the NS constructor
Instances
| PrintfArg Natural | Since: base-4.8.0.0 |
Defined in Text.Printf | |
| Bits Natural | Since: base-4.8.0 |
Defined in GHC.Internal.Bits Methods (.&.) :: Natural -> Natural -> Natural # (.|.) :: Natural -> Natural -> Natural # xor :: Natural -> Natural -> Natural # complement :: Natural -> Natural # shift :: Natural -> Int -> Natural # rotate :: Natural -> Int -> Natural # setBit :: Natural -> Int -> Natural # clearBit :: Natural -> Int -> Natural # complementBit :: Natural -> Int -> Natural # testBit :: Natural -> Int -> Bool # bitSizeMaybe :: Natural -> Maybe Int # shiftL :: Natural -> Int -> Natural # unsafeShiftL :: Natural -> Int -> Natural # shiftR :: Natural -> Int -> Natural # unsafeShiftR :: Natural -> Int -> Natural # rotateL :: Natural -> Int -> Natural # | |
| Enum Natural | Since: base-4.8.0.0 |
| Num Natural | Note that Since: base-4.8.0.0 |
| Read Natural | Since: base-4.8.0.0 |
| Integral Natural | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real | |
| Real Natural | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real Methods toRational :: Natural -> Rational # | |
| Show Natural | Since: base-4.8.0.0 |
| Eq Natural | |
| Ord Natural | |
| KnownNat n => HasResolution (n :: Nat) | For example, |
Defined in Data.Fixed Methods resolution :: p n -> Integer # | |
| TestCoercion SNat | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| TestEquality SNat | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| type Compare (a :: Natural) (b :: Natural) | |
Defined in GHC.Internal.Data.Type.Ord | |
type family (a :: Natural) - (b :: Natural) :: Natural where ... infixl 6 #
Subtraction of type-level naturals.
Since: base-4.7.0.0
class KnownNat (n :: Nat) where #
This class gives the integer associated with a type-level natural. There are instances of the class for every concrete literal: 0, 1, 2, etc.
Since: base-4.7.0.0
class KnownSymbol (n :: Symbol) where #
This class gives the string associated with a type-level symbol. There are instances of the class for every concrete literal: "hello", etc.
Since: base-4.7.0.0
Methods
symbolSing :: SSymbol n #
type family TypeError (a :: ErrorMessage) :: b where ... #
The type-level equivalent of error.
The polymorphic kind of this type allows it to be used in several settings. For instance, it can be used as a constraint, e.g. to provide a better error message for a non-existent instance,
-- in a context
instance TypeError (Text "Cannot Show functions." :$$:
Text "Perhaps there is a missing argument?")
=> Show (a -> b) where
showsPrec = error "unreachable"
It can also be placed on the right-hand side of a type-level function to provide an error for an invalid case,
type family ByteSize x where
ByteSize Word16 = 2
ByteSize Word8 = 1
ByteSize a = TypeError (Text "The type " :<>: ShowType a :<>:
Text " is not exportable.")
Since: base-4.9.0.0
type family AppendSymbol (a :: Symbol) (b :: Symbol) :: Symbol where ... #
Concatenation of type-level symbols.
Since: base-4.10.0.0
type family (a :: Natural) + (b :: Natural) :: Natural where ... infixl 6 #
Addition of type-level naturals.
Since: base-4.7.0.0
type family (a :: Natural) * (b :: Natural) :: Natural where ... infixl 7 #
Multiplication of type-level naturals.
Since: base-4.7.0.0
type family (a :: Natural) ^ (b :: Natural) :: Natural where ... infixr 8 #
Exponentiation of type-level naturals.
Since: base-4.7.0.0
type family CmpSymbol (a :: Symbol) (b :: Symbol) :: Ordering where ... #
Comparison of type-level symbols, as a function.
Since: base-4.7.0.0
type family CmpNat (a :: Natural) (b :: Natural) :: Ordering where ... #
Comparison of type-level naturals, as a function.
Since: base-4.7.0.0
type family CmpChar (a :: Char) (b :: Char) :: Ordering where ... #
Comparison of type-level characters.
Since: base-4.16.0.0
type family Div (a :: Natural) (b :: Natural) :: Natural where ... infixl 7 #
Division (round down) of natural numbers.
Div x 0 is undefined (i.e., it cannot be reduced).
Since: base-4.11.0.0
type family Mod (a :: Natural) (b :: Natural) :: Natural where ... infixl 7 #
Modulus of natural numbers.
Mod x 0 is undefined (i.e., it cannot be reduced).
Since: base-4.11.0.0
type family Log2 (a :: Natural) :: Natural where ... #
Log base 2 (round down) of natural numbers.
Log 0 is undefined (i.e., it cannot be reduced).
Since: base-4.11.0.0
type family ConsSymbol (a :: Char) (b :: Symbol) :: Symbol where ... #
Extending a type-level symbol with a type-level character
Since: base-4.16.0.0
type family CharToNat (a :: Char) :: Natural where ... #
Convert a character to its Unicode code point (cf. ord)
Since: base-4.16.0.0
type family NatToChar (a :: Natural) :: Char where ... #
Convert a Unicode code point to a character (cf. chr)
Since: base-4.16.0.0
pattern (:<>:) :: ErrorMessage -> ErrorMessage -> ErrorMessage infixl 6 #
Put two pieces of error message next to each other.
pattern (:$$:) :: ErrorMessage -> ErrorMessage -> ErrorMessage infixl 5 #
Stack two pieces of error message on top of each other.
pattern ShowType :: t -> ErrorMessage #
Pretty print the type.
ShowType :: k -> ErrorMessage
type (<=) (x :: t) (y :: t) = Assert (x <=? y) (LeErrMsg x y :: Constraint) infix 4 #
Comparison (<=) of comparable types, as a constraint.
Since: base-4.16.0.0
type (<=?) (m :: k) (n :: k) = OrdCond (Compare m n) 'True 'True 'False infix 4 #
Comparison (<=) of comparable types, as a function.
Since: base-4.16.0.0
data OrderingI (a :: k) (b :: k) where #
Ordering data type for type literals that provides proof of their ordering.
Since: base-4.16.0.0
Constructors
| LTI :: forall {k} (a :: k) (b :: k). Compare a b ~ 'LT => OrderingI a b | |
| EQI :: forall {k} (a :: k). Compare a a ~ 'EQ => OrderingI a a | |
| GTI :: forall {k} (a :: k) (b :: k). Compare a b ~ 'GT => OrderingI a b |
A value-level witness for a type-level natural number. This is commonly
referred to as a singleton type, as for each n, there is a single value
that inhabits the type (aside from bottom).SNat n
The definition of SNat is intentionally left abstract. To obtain an SNat
value, use one of the following:
- The
natSingmethod ofKnownNat. - The
SNatpattern synonym. - The
withSomeSNatfunction, which creates anSNatfrom aNaturalnumber.
Since: base-4.18.0.0
Instances
| TestCoercion SNat | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| TestEquality SNat | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| Show (SNat n) | Since: base-4.18.0.0 |
| Eq (SNat n) | Since: base-4.19.0.0 |
| Ord (SNat n) | Since: base-4.19.0.0 |
pattern SNat :: () => KnownNat n => SNat n #
A explicitly bidirectional pattern synonym relating an SNat to a
KnownNat constraint.
As an expression: Constructs an explicit value from an
implicit SNat n constraint:KnownNat n
SNat @n ::KnownNatn =>SNatn
As a pattern: Matches on an explicit value bringing
an implicit SNat n constraint into scope:KnownNat n
f :: SNat n -> ..
f SNat = {- KnownNat n in scope -}
Since: base-4.18.0.0
This type represents unknown type-level natural numbers.
Since: base-4.10.0.0
A type synonym for Natural.
Previously, this was an opaque data type, but it was changed to a type synonym.
Since: base-4.16.0.0
someNatVal :: Integer -> Maybe SomeNat #
Convert an integer into an unknown type-level natural.
Since: base-4.7.0.0
sameNat :: forall (a :: Nat) (b :: Nat) proxy1 proxy2. (KnownNat a, KnownNat b) => proxy1 a -> proxy2 b -> Maybe (a :~: b) #
We either get evidence that this function was instantiated with the
same type-level numbers, or Nothing.
Since: base-4.7.0.0
decideNat :: forall (a :: Nat) (b :: Nat) proxy1 proxy2. (KnownNat a, KnownNat b) => proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b) #
We either get evidence that this function was instantiated with the same type-level numbers, or that the type-level numbers are distinct.
Since: base-4.19.0.0
cmpNat :: forall (a :: Nat) (b :: Nat) proxy1 proxy2. (KnownNat a, KnownNat b) => proxy1 a -> proxy2 b -> OrderingI a b #
Like sameNat, but if the numbers aren't equal, this additionally
provides proof of LT or GT.
Since: base-4.16.0.0
fromSNat :: forall (n :: Nat). SNat n -> Integer #
Return the Integer corresponding to n in an value.
The returned SNat nInteger is always non-negative.
For a version of this function that returns a Natural instead of an
Integer, see fromSNat in GHC.TypeNats.
Since: base-4.18.0.0
withKnownNat :: forall (n :: Nat) r. SNat n -> (KnownNat n => r) -> r #
withSomeSNat :: Integer -> (forall (n :: Nat). Maybe (SNat n) -> r) -> r #
Attempt to convert an Integer into an value, where SNat nn is a
fresh type-level natural number. If the Integer argument is non-negative,
invoke the continuation with Just sn, where sn is the value.
If the SNat nInteger argument is negative, invoke the continuation with
Nothing.
For a version of this function where the continuation uses 'SNat n
instead of Maybe (SNat n)@, see withSomeSNat in GHC.TypeNats.
Since: base-4.18.0.0
A value-level witness for a type-level character. This is commonly referred
to as a singleton type, as for each c, there is a single value that
inhabits the type (aside from bottom).SChar c
The definition of SChar is intentionally left abstract. To obtain an
SChar value, use one of the following:
- The
charSingmethod ofKnownChar. - The
SCharpattern synonym. - The
withSomeSCharfunction, which creates anSCharfrom aChar.
Since: base-4.18.0.0
Instances
| TestCoercion SChar | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeLits | |
| TestEquality SChar | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeLits | |
| Show (SChar c) | Since: base-4.18.0.0 |
| Eq (SChar c) | Since: base-4.19.0.0 |
| Ord (SChar c) | Since: base-4.19.0.0 |
Defined in GHC.Internal.TypeLits | |
pattern SChar :: () => KnownChar c => SChar c #
A explicitly bidirectional pattern synonym relating an SChar to a
KnownChar constraint.
As an expression: Constructs an explicit value from an
implicit SChar c constraint:KnownChar c
SChar @c ::KnownCharc =>SCharc
As a pattern: Matches on an explicit value bringing
an implicit SChar c constraint into scope:KnownChar c
f :: SChar c -> ..
f SChar = {- KnownChar c in scope -}
Since: base-4.18.0.0
A value-level witness for a type-level symbol. This is commonly referred
to as a singleton type, as for each s, there is a single value that
inhabits the type (aside from bottom).SSymbol s
The definition of SSymbol is intentionally left abstract. To obtain an
SSymbol value, use one of the following:
- The
symbolSingmethod ofKnownSymbol. - The
SSymbolpattern synonym. - The
withSomeSSymbolfunction, which creates anSSymbolfrom aString.
Since: base-4.18.0.0
Instances
| TestCoercion SSymbol | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeLits | |
| TestEquality SSymbol | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeLits | |
| Show (SSymbol s) | Since: base-4.18.0.0 |
| Eq (SSymbol s) | Since: base-4.19.0.0 |
| Ord (SSymbol s) | Since: base-4.19.0.0 |
pattern SSymbol :: () => KnownSymbol s => SSymbol s #
A explicitly bidirectional pattern synonym relating an SSymbol to a
KnownSymbol constraint.
As an expression: Constructs an explicit value from an
implicit SSymbol s constraint:KnownSymbol s
SSymbol @s ::KnownSymbols =>SSymbols
As a pattern: Matches on an explicit value bringing
an implicit SSymbol s constraint into scope:KnownSymbol s
f :: SSymbol s -> ..
f SSymbol = {- KnownSymbol s in scope -}
Since: base-4.18.0.0
data SomeSymbol #
This type represents unknown type-level symbols.
Constructors
| KnownSymbol n => SomeSymbol (Proxy n) | Since: base-4.7.0.0 |
Instances
| Read SomeSymbol | Since: base-4.7.0.0 |
Defined in GHC.Internal.TypeLits Methods readsPrec :: Int -> ReadS SomeSymbol # readList :: ReadS [SomeSymbol] # readPrec :: ReadPrec SomeSymbol # readListPrec :: ReadPrec [SomeSymbol] # | |
| Show SomeSymbol | Since: base-4.7.0.0 |
Defined in GHC.Internal.TypeLits Methods showsPrec :: Int -> SomeSymbol -> ShowS # show :: SomeSymbol -> String # showList :: [SomeSymbol] -> ShowS # | |
| Eq SomeSymbol | Since: base-4.7.0.0 |
Defined in GHC.Internal.TypeLits | |
| Ord SomeSymbol | Since: base-4.7.0.0 |
Defined in GHC.Internal.TypeLits Methods compare :: SomeSymbol -> SomeSymbol -> Ordering # (<) :: SomeSymbol -> SomeSymbol -> Bool # (<=) :: SomeSymbol -> SomeSymbol -> Bool # (>) :: SomeSymbol -> SomeSymbol -> Bool # (>=) :: SomeSymbol -> SomeSymbol -> Bool # max :: SomeSymbol -> SomeSymbol -> SomeSymbol # min :: SomeSymbol -> SomeSymbol -> SomeSymbol # | |
symbolVal :: forall (n :: Symbol) proxy. KnownSymbol n => proxy n -> String #
Since: base-4.7.0.0
symbolVal' :: forall (n :: Symbol). KnownSymbol n => Proxy# n -> String #
Since: base-4.8.0.0
someSymbolVal :: String -> SomeSymbol #
Convert a string into an unknown type-level symbol.
Since: base-4.7.0.0
someCharVal :: Char -> SomeChar #
Convert a character into an unknown type-level char.
Since: base-4.16.0.0
sameSymbol :: forall (a :: Symbol) (b :: Symbol) proxy1 proxy2. (KnownSymbol a, KnownSymbol b) => proxy1 a -> proxy2 b -> Maybe (a :~: b) #
We either get evidence that this function was instantiated with the
same type-level symbols, or Nothing.
Since: base-4.7.0.0
decideSymbol :: forall (a :: Symbol) (b :: Symbol) proxy1 proxy2. (KnownSymbol a, KnownSymbol b) => proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b) #
We either get evidence that this function was instantiated with the same type-level symbols, or that the type-level symbols are distinct.
Since: base-4.19.0.0
sameChar :: forall (a :: Char) (b :: Char) proxy1 proxy2. (KnownChar a, KnownChar b) => proxy1 a -> proxy2 b -> Maybe (a :~: b) #
We either get evidence that this function was instantiated with the
same type-level characters, or Nothing.
Since: base-4.16.0.0
decideChar :: forall (a :: Char) (b :: Char) proxy1 proxy2. (KnownChar a, KnownChar b) => proxy1 a -> proxy2 b -> Either ((a :~: b) -> Void) (a :~: b) #
We either get evidence that this function was instantiated with the same type-level characters, or that the type-level characters are distinct.
Since: base-4.19.0.0
cmpSymbol :: forall (a :: Symbol) (b :: Symbol) proxy1 proxy2. (KnownSymbol a, KnownSymbol b) => proxy1 a -> proxy2 b -> OrderingI a b #
Like sameSymbol, but if the symbols aren't equal, this additionally
provides proof of LT or GT.
Since: base-4.16.0.0
cmpChar :: forall (a :: Char) (b :: Char) proxy1 proxy2. (KnownChar a, KnownChar b) => proxy1 a -> proxy2 b -> OrderingI a b #
Like sameChar, but if the Chars aren't equal, this additionally
provides proof of LT or GT.
Since: base-4.16.0.0
fromSSymbol :: forall (s :: Symbol). SSymbol s -> String #
Return the String corresponding to s in an value.SSymbol s
Since: base-4.18.0.0
withKnownSymbol :: forall (s :: Symbol) r. SSymbol s -> (KnownSymbol s => r) -> r #
Convert an explicit value into an implicit SSymbol s
constraint.KnownSymbol s
Since: base-4.18.0.0
withSomeSSymbol :: String -> (forall (s :: Symbol). SSymbol s -> r) -> r #
withKnownChar :: forall (c :: Char) r. SChar c -> (KnownChar c => r) -> r #
withSomeSChar :: Char -> (forall (c :: Char). SChar c -> r) -> r #
module Incipit.Fixed
module Incipit.Foldable
module Incipit.Fractional
rem :: Integral a => a -> a -> Maybe a Source #
integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
mod :: Integral a => a -> a -> Maybe a Source #
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
Natural number
Invariant: numbers <= 0xffffffffffffffff use the NS constructor
Instances
| PrintfArg Natural | Since: base-4.8.0.0 |
Defined in Text.Printf | |
| Bits Natural | Since: base-4.8.0 |
Defined in GHC.Internal.Bits Methods (.&.) :: Natural -> Natural -> Natural # (.|.) :: Natural -> Natural -> Natural # xor :: Natural -> Natural -> Natural # complement :: Natural -> Natural # shift :: Natural -> Int -> Natural # rotate :: Natural -> Int -> Natural # setBit :: Natural -> Int -> Natural # clearBit :: Natural -> Int -> Natural # complementBit :: Natural -> Int -> Natural # testBit :: Natural -> Int -> Bool # bitSizeMaybe :: Natural -> Maybe Int # shiftL :: Natural -> Int -> Natural # unsafeShiftL :: Natural -> Int -> Natural # shiftR :: Natural -> Int -> Natural # unsafeShiftR :: Natural -> Int -> Natural # rotateL :: Natural -> Int -> Natural # | |
| Enum Natural | Since: base-4.8.0.0 |
| Num Natural | Note that Since: base-4.8.0.0 |
| Read Natural | Since: base-4.8.0.0 |
| Integral Natural | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real | |
| Real Natural | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real Methods toRational :: Natural -> Rational # | |
| Show Natural | Since: base-4.8.0.0 |
| Eq Natural | |
| Ord Natural | |
| KnownNat n => HasResolution (n :: Nat) | For example, |
Defined in Data.Fixed Methods resolution :: p n -> Integer # | |
| TestCoercion SNat | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| TestEquality SNat | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| type Compare (a :: Natural) (b :: Natural) | |
Defined in GHC.Internal.Data.Type.Ord | |
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
| MonadIO IO | Since: base-4.9.0.0 |
Defined in Control.Monad.IO.Class | |
| Alternative IO | Takes the first non-throwing Since: base-4.9.0.0 |
| Applicative IO | Since: base-2.1 |
| Functor IO | Since: base-2.1 |
| Monad IO | Since: base-2.1 |
| MonadPlus IO | Takes the first non-throwing Since: base-4.9.0.0 |
| MonadFail IO | Since: base-4.9.0.0 |
Defined in GHC.Internal.Control.Monad.Fail | |
| MArray TArray e IO | Writes are slow in |
Defined in Control.Concurrent.STM.TArray Methods getBounds :: Ix i => TArray i e -> IO (i, i) # getNumElements :: Ix i => TArray i e -> IO Int # newArray :: Ix i => (i, i) -> e -> IO (TArray i e) # newArray_ :: Ix i => (i, i) -> IO (TArray i e) # unsafeNewArray_ :: Ix i => (i, i) -> IO (TArray i e) # | |
| 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 | |
| Monoid a => Monoid (IO a) | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (IO a) | Since: base-4.10.0.0 |
print :: Show a => a -> IO () #
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]])
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.
Arguments
| :: Show a | |
| => Int | the operator precedence of the enclosing
context (a number from |
| -> a | the value to be converted to a |
| -> ShowS |
showString :: String -> ShowS #
utility function converting a String to a show function that
simply prepends the string unchanged.