Safe Haskell  SafeInferred 

Language  Haskell2010 
Reexports from base
.
Synopsis
 class Functor f => Applicative (f :: Type > Type) where
 class Applicative f => Alternative (f :: Type > Type) where
 newtype Const a (b :: k) = Const {
 getConst :: a
 newtype ZipList a = ZipList {
 getZipList :: [a]
 (<**>) :: 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)
 (&&&) :: 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
 class (Typeable e, Show e) => Exception e
 data SomeException = Exception e => SomeException e
 class (Alternative m, Monad m) => MonadPlus (m :: Type > Type) where
 class Applicative m => Monad (m :: Type > Type) where
 forever :: Applicative f => f a > f b
 guard :: Alternative f => Bool > f ()
 join :: Monad m => m (m a) > m a
 (=<<) :: 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
 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
 class Monad m => MonadFail (m :: Type > Type) where
 module Control.Monad.IO.Class
 class Bifunctor (p :: Type > Type > Type) where
 xor :: Bits a => a > a > a
 toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a > Maybe b
 data Bool
 otherwise :: Bool
 (&&) :: Bool > Bool > Bool
 () :: Bool > Bool > Bool
 not :: Bool > Bool
 bool :: a > a > Bool > a
 data Char
 chr :: Int > Char
 class a ~R# b => Coercible (a :: k) (b :: k)
 coerce :: forall {k :: RuntimeRep} (a :: TYPE k) (b :: TYPE k). Coercible a b => a > b
 module Data.Either
 class Eq a where
 ($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a > b) > a > b
 id :: a > a
 const :: a > b > 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
 void :: Functor f => f a > f ()
 (<&>) :: Functor f => f a > (a > b) > f b
 ($>) :: Functor f => f a > b > f b
 newtype Compose (f :: k > Type) (g :: k1 > k) (a :: k1) = Compose {
 getCompose :: f (g a)
 class Contravariant (f :: Type > Type) where
 (>$<) :: Contravariant f => (a > b) > f b > f a
 newtype Identity a = Identity {
 runIdentity :: a
 data Int
 data Int8
 data Int16
 data Int32
 data Int64
 data Constraint
 type Type = TYPE LiftedRep
 zipWith :: (a > b > c) > [a] > [b] > [c]
 sortBy :: (a > a > Ordering) > [a] > [a]
 genericLength :: Num i => [a] > i
 genericReplicate :: Integral i => i > a > [a]
 genericTake :: Integral i => i > [a] > [a]
 genericDrop :: Integral i => i > [a] > [a]
 genericSplitAt :: Integral i => i > [a] > ([a], [a])
 filter :: (a > Bool) > [a] > [a]
 unfoldr :: (b > Maybe (a, b)) > b > [a]
 transpose :: [[a]] > [[a]]
 sortOn :: Ord b => (a > b) > [a] > [a]
 (++) :: [a] > [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)]
 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]
 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
 uncurry :: (a > b > c) > (a, b) > c
 snd :: (a, b) > b
 curry :: ((a, b) > c) > a > b > c
 swap :: (a, b) > (b, a)
 class Typeable (a :: k)
 data Void
 data Word8
 data Word
 data Word64
 data Word32
 data Word16
 ord :: Char > Int
 seq :: forall {r :: RuntimeRep} a (b :: TYPE r). a > b > b
 minInt :: Int
 maxInt :: Int
 ($!) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a > b) > a > b
 class Bounded a where
 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]
 error :: forall (r :: RuntimeRep) (a :: TYPE r). HasCallStack => [Char] > a
 undefined :: forall (r :: RuntimeRep) (a :: TYPE r). 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
 class IsLabel (x :: Symbol) a where
 fromLabel :: a
 type Rational = Ratio Integer
 class Num a => Fractional a where
 fromRational :: Rational > a
 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
 even :: Integral a => a > Bool
 fromIntegral :: (Integral a, Num b) => a > b
 realToFrac :: (Real a, Fractional b) => a > b
 (^) :: (Num a, Integral b) => a > b > a
 numerator :: Ratio a > a
 denominator :: Ratio a > a
 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)
 class KnownSymbol (n :: Symbol)
 class KnownChar (n :: Char)
 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 ...
 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 SomeNat = KnownNat n => SomeNat (Proxy n)
 type Nat = Natural
 data SomeChar = KnownChar n => SomeChar (Proxy n)
 data SomeSymbol = KnownSymbol n => SomeSymbol (Proxy n)
 pattern ShowType :: t > ErrorMessage
 pattern (:<>:) :: ErrorMessage > ErrorMessage > ErrorMessage
 pattern (:$$:) :: ErrorMessage > ErrorMessage > ErrorMessage
 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)
 cmpNat :: forall (a :: Nat) (b :: Nat) proxy1 proxy2. (KnownNat a, KnownNat b) => proxy1 a > proxy2 b > OrderingI a b
 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)
 sameChar :: forall (a :: Char) (b :: Char) proxy1 proxy2. (KnownChar a, KnownChar b) => proxy1 a > proxy2 b > Maybe (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
 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
 type FilePath = String
 putStrLn :: String > IO ()
 print :: Show a => a > IO ()
 putStr :: String > IO ()
 showsPrec :: Show a => Int > a > ShowS
 showString :: String > ShowS
 showParen :: Bool > ShowS > ShowS
Documentation
class Functor f => Applicative (f :: Type > Type) where Source #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(<*>
) =liftA2
id
liftA2
f x y = f<$>
x<*>
y
Further, any definition must satisfy the following:
 Identity
pure
id
<*>
v = v Composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w) Homomorphism
pure
f<*>
pure
x =pure
(f x) Interchange
u
<*>
pure
y =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
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Lift a value.
(<*>) :: f (a > b) > f a > f b infixl 4 Source #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
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 Source #
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)
(*>) :: f a > f b > f b infixl 4 Source #
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 3
Just 3
>>>
Nothing *> Just 3
Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>>
import Data.Char
>>>
import 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 Source #
Sequence actions, discarding the value of the second argument.
Instances
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: base2.1 
Applicative Complex  Since: base4.9.0.0 
Applicative Identity  Since: base4.8.0.0 
Defined in Data.Functor.Identity  
Applicative First  Since: base4.8.0.0 
Applicative Last  Since: base4.8.0.0 
Applicative Down  Since: base4.11.0.0 
Applicative First  Since: base4.9.0.0 
Applicative Last  Since: base4.9.0.0 
Applicative Max  Since: base4.9.0.0 
Applicative Min  Since: base4.9.0.0 
Applicative Par1  Since: base4.9.0.0 
Applicative P  Since: base4.5.0.0 
Applicative ReadP  Since: base4.6.0.0 
Applicative Seq  Since: containers0.5.4 
Applicative DList  
Applicative IO  Since: base2.1 
Applicative NonEmpty  Since: base4.9.0.0 
Applicative Maybe  Since: base2.1 
Applicative Solo  Since: base4.15 
Applicative []  Since: base2.1 
Monad m => Applicative (WrappedMonad m)  Since: base2.1 
Defined in Control.Applicative pure :: a > WrappedMonad m a Source # (<*>) :: WrappedMonad m (a > b) > WrappedMonad m a > WrappedMonad m b Source # liftA2 :: (a > b > c) > WrappedMonad m a > WrappedMonad m b > WrappedMonad m c Source # (*>) :: WrappedMonad m a > WrappedMonad m b > WrappedMonad m b Source # (<*) :: WrappedMonad m a > WrappedMonad m b > WrappedMonad m a Source #  
Arrow a => Applicative (ArrowMonad a)  Since: base4.6.0.0 
Defined in Control.Arrow pure :: a0 > ArrowMonad a a0 Source # (<*>) :: ArrowMonad a (a0 > b) > ArrowMonad a a0 > ArrowMonad a b Source # liftA2 :: (a0 > b > c) > ArrowMonad a a0 > ArrowMonad a b > ArrowMonad a c Source # (*>) :: ArrowMonad a a0 > ArrowMonad a b > ArrowMonad a b Source # (<*) :: ArrowMonad a a0 > ArrowMonad a b > ArrowMonad a a0 Source #  
Applicative (Either e)  Since: base3.0 
Defined in Data.Either  
Applicative (Proxy :: Type > Type)  Since: base4.7.0.0 
Applicative (U1 :: Type > Type)  Since: base4.9.0.0 
Monoid a => Applicative ((,) a)  For tuples, the ("hello ", (+15)) <*> ("world!", 2002) ("hello world!",2017) Since: base2.1 
Arrow a => Applicative (WrappedArrow a b)  Since: base2.1 
Defined in Control.Applicative pure :: a0 > WrappedArrow a b a0 Source # (<*>) :: WrappedArrow a b (a0 > b0) > WrappedArrow a b a0 > WrappedArrow a b b0 Source # liftA2 :: (a0 > b0 > c) > WrappedArrow a b a0 > WrappedArrow a b b0 > WrappedArrow a b c Source # (*>) :: WrappedArrow a b a0 > WrappedArrow a b b0 > WrappedArrow a b b0 Source # (<*) :: WrappedArrow a b a0 > WrappedArrow a b b0 > WrappedArrow a b a0 Source #  
Applicative m => Applicative (Kleisli m a)  Since: base4.14.0.0 
Defined in Control.Arrow pure :: a0 > Kleisli m a a0 Source # (<*>) :: Kleisli m a (a0 > b) > Kleisli m a a0 > Kleisli m a b Source # liftA2 :: (a0 > b > c) > Kleisli m a a0 > Kleisli m a b > Kleisli m a c Source # (*>) :: Kleisli m a a0 > Kleisli m a b > Kleisli m a b Source # (<*) :: Kleisli m a a0 > Kleisli m a b > Kleisli m a a0 Source #  
Monoid m => Applicative (Const m :: Type > Type)  Since: base2.0.1 
Applicative f => Applicative (Ap f)  Since: base4.12.0.0 
(Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f)  Since: base4.17.0.0 
Defined in GHC.Generics pure :: a > Generically1 f a Source # (<*>) :: Generically1 f (a > b) > Generically1 f a > Generically1 f b Source # liftA2 :: (a > b > c) > Generically1 f a > Generically1 f b > Generically1 f c Source # (*>) :: Generically1 f a > Generically1 f b > Generically1 f b Source # (<*) :: Generically1 f a > Generically1 f b > Generically1 f a Source #  
Applicative f => Applicative (Rec1 f)  Since: base4.9.0.0 
(Applicative f, Monad f) => Applicative (WhenMissing f x)  Equivalent to Since: containers0.5.9 
Defined in Data.IntMap.Internal pure :: a > WhenMissing f x a Source # (<*>) :: WhenMissing f x (a > b) > WhenMissing f x a > WhenMissing f x b Source # liftA2 :: (a > b > c) > WhenMissing f x a > WhenMissing f x b > WhenMissing f x c Source # (*>) :: WhenMissing f x a > WhenMissing f x b > WhenMissing f x b Source # (<*) :: WhenMissing f x a > WhenMissing f x b > WhenMissing f x a Source #  
(Monoid a, Monoid b) => Applicative ((,,) a b)  Since: base4.14.0.0 
Defined in GHC.Base  
(Applicative f, Applicative g) => Applicative (Product f g)  Since: base4.9.0.0 
Defined in Data.Functor.Product pure :: a > Product f g a Source # (<*>) :: Product f g (a > b) > Product f g a > Product f g b Source # liftA2 :: (a > b > c) > Product f g a > Product f g b > Product f g c Source # (*>) :: Product f g a > Product f g b > Product f g b Source # (<*) :: Product f g a > Product f g b > Product f g a Source #  
(Applicative f, Applicative g) => Applicative (f :*: g)  Since: base4.9.0.0 
Defined in GHC.Generics  
Monoid c => Applicative (K1 i c :: Type > Type)  Since: base4.12.0.0 
(Monad f, Applicative f) => Applicative (WhenMatched f x y)  Equivalent to Since: containers0.5.9 
Defined in Data.IntMap.Internal pure :: a > WhenMatched f x y a Source # (<*>) :: WhenMatched f x y (a > b) > WhenMatched f x y a > WhenMatched f x y b Source # liftA2 :: (a > b > c) > WhenMatched f x y a > WhenMatched f x y b > WhenMatched f x y c Source # (*>) :: WhenMatched f x y a > WhenMatched f x y b > WhenMatched f x y b Source # (<*) :: WhenMatched f x y a > WhenMatched f x y b > WhenMatched f x y a Source #  
(Applicative f, Monad f) => Applicative (WhenMissing f k x)  Equivalent to Since: containers0.5.9 
Defined in Data.Map.Internal pure :: a > WhenMissing f k x a Source # (<*>) :: WhenMissing f k x (a > b) > WhenMissing f k x a > WhenMissing f k x b Source # liftA2 :: (a > b > c) > WhenMissing f k x a > WhenMissing f k x b > WhenMissing f k x c Source # (*>) :: WhenMissing f k x a > WhenMissing f k x b > WhenMissing f k x b Source # (<*) :: WhenMissing f k x a > WhenMissing f k x b > WhenMissing f k x a Source #  
(Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c)  Since: base4.14.0.0 
Defined in GHC.Base pure :: a0 > (a, b, c, a0) Source # (<*>) :: (a, b, c, a0 > b0) > (a, b, c, a0) > (a, b, c, b0) Source # liftA2 :: (a0 > b0 > c0) > (a, b, c, a0) > (a, b, c, b0) > (a, b, c, c0) Source # (*>) :: (a, b, c, a0) > (a, b, c, b0) > (a, b, c, b0) Source # (<*) :: (a, b, c, a0) > (a, b, c, b0) > (a, b, c, a0) Source #  
Applicative ((>) r)  Since: base2.1 
(Applicative f, Applicative g) => Applicative (Compose f g)  Since: base4.9.0.0 
Defined in Data.Functor.Compose pure :: a > Compose f g a Source # (<*>) :: Compose f g (a > b) > Compose f g a > Compose f g b Source # liftA2 :: (a > b > c) > Compose f g a > Compose f g b > Compose f g c Source # (*>) :: Compose f g a > Compose f g b > Compose f g b Source # (<*) :: Compose f g a > Compose f g b > Compose f g a Source #  
(Applicative f, Applicative g) => Applicative (f :.: g)  Since: base4.9.0.0 
Defined in GHC.Generics  
Applicative f => Applicative (M1 i c f)  Since: base4.9.0.0 
Defined in GHC.Generics  
(Monad f, Applicative f) => Applicative (WhenMatched f k x y)  Equivalent to Since: containers0.5.9 
Defined in Data.Map.Internal pure :: a > WhenMatched f k x y a Source # (<*>) :: WhenMatched f k x y (a > b) > WhenMatched f k x y a > WhenMatched f k x y b Source # liftA2 :: (a > b > c) > WhenMatched f k x y a > WhenMatched f k x y b > WhenMatched f k x y c Source # (*>) :: WhenMatched f k x y a > WhenMatched f k x y b > WhenMatched f k x y b Source # (<*) :: WhenMatched f k x y a > WhenMatched f k x y b > WhenMatched f k x y a Source # 
class Applicative f => Alternative (f :: Type > Type) where Source #
A monoid on applicative functors.
If defined, some
and many
should be the least solutions
of the equations:
The identity of <>
(<>) :: f a > f a > f a infixl 3 Source #
An associative binary operation
One or more.
Zero or more.
Instances
newtype Const a (b :: k) Source #
The Const
functor.
Instances
Generic1 (Const a :: k > Type)  
Bifunctor (Const :: Type > Type > Type)  Since: base4.8.0.0 
Foldable (Const m :: Type > Type)  Since: base4.7.0.0 
Defined in Data.Functor.Const fold :: Monoid m0 => Const m m0 > m0 Source # foldMap :: Monoid m0 => (a > m0) > Const m a > m0 Source # foldMap' :: Monoid m0 => (a > m0) > Const m a > m0 Source # foldr :: (a > b > b) > b > Const m a > b Source # foldr' :: (a > b > b) > b > Const m a > b Source # foldl :: (b > a > b) > b > Const m a > b Source # foldl' :: (b > a > b) > b > Const m a > b Source # foldr1 :: (a > a > a) > Const m a > a Source # foldl1 :: (a > a > a) > Const m a > a Source # toList :: Const m a > [a] Source # null :: Const m a > Bool Source # length :: Const m a > Int Source # elem :: Eq a => a > Const m a > Bool Source # maximum :: Ord a => Const m a > a Source # minimum :: Ord a => Const m a > a Source #  
Contravariant (Const a :: Type > Type)  
Traversable (Const m :: Type > Type)  Since: base4.7.0.0 
Defined in Data.Traversable  
Monoid m => Applicative (Const m :: Type > Type)  Since: base2.0.1 
Functor (Const m :: Type > Type)  Since: base2.1 
IsString a => IsString (Const a b)  Since: base4.9.0.0 
Defined in Data.String fromString :: String > Const a b Source #  
Storable a => Storable (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const sizeOf :: Const a b > Int Source # alignment :: Const a b > Int Source # peekElemOff :: Ptr (Const a b) > Int > IO (Const a b) Source # pokeElemOff :: Ptr (Const a b) > Int > Const a b > IO () Source # peekByteOff :: Ptr b0 > Int > IO (Const a b) Source # pokeByteOff :: Ptr b0 > Int > Const a b > IO () Source #  
Monoid a => Monoid (Const a b)  Since: base4.9.0.0 
Semigroup a => Semigroup (Const a b)  Since: base4.9.0.0 
Bits a => Bits (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const (.&.) :: Const a b > Const a b > Const a b Source # (..) :: Const a b > Const a b > Const a b Source # xor :: Const a b > Const a b > Const a b Source # complement :: Const a b > Const a b Source # shift :: Const a b > Int > Const a b Source # rotate :: Const a b > Int > Const a b Source # zeroBits :: Const a b Source # bit :: Int > Const a b Source # setBit :: Const a b > Int > Const a b Source # clearBit :: Const a b > Int > Const a b Source # complementBit :: Const a b > Int > Const a b Source # testBit :: Const a b > Int > Bool Source # bitSizeMaybe :: Const a b > Maybe Int Source # bitSize :: Const a b > Int Source # isSigned :: Const a b > Bool Source # shiftL :: Const a b > Int > Const a b Source # unsafeShiftL :: Const a b > Int > Const a b Source # shiftR :: Const a b > Int > Const a b Source # unsafeShiftR :: Const a b > Int > Const a b Source # rotateL :: Const a b > Int > Const a b Source #  
FiniteBits a => FiniteBits (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const finiteBitSize :: Const a b > Int Source # countLeadingZeros :: Const a b > Int Source # countTrailingZeros :: Const a b > Int Source #  
Bounded a => Bounded (Const a b)  Since: base4.9.0.0 
Enum a => Enum (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const succ :: Const a b > Const a b Source # pred :: Const a b > Const a b Source # toEnum :: Int > Const a b Source # fromEnum :: Const a b > Int Source # enumFrom :: Const a b > [Const a b] Source # enumFromThen :: Const a b > Const a b > [Const a b] Source # enumFromTo :: Const a b > Const a b > [Const a b] Source # enumFromThenTo :: Const a b > Const a b > Const a b > [Const a b] Source #  
Floating a => Floating (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const exp :: Const a b > Const a b Source # log :: Const a b > Const a b Source # sqrt :: Const a b > Const a b Source # (**) :: Const a b > Const a b > Const a b Source # logBase :: Const a b > Const a b > Const a b Source # sin :: Const a b > Const a b Source # cos :: Const a b > Const a b Source # tan :: Const a b > Const a b Source # asin :: Const a b > Const a b Source # acos :: Const a b > Const a b Source # atan :: Const a b > Const a b Source # sinh :: Const a b > Const a b Source # cosh :: Const a b > Const a b Source # tanh :: Const a b > Const a b Source # asinh :: Const a b > Const a b Source # acosh :: Const a b > Const a b Source # atanh :: Const a b > Const a b Source # log1p :: Const a b > Const a b Source # expm1 :: Const a b > Const a b Source #  
RealFloat a => RealFloat (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const floatRadix :: Const a b > Integer Source # floatDigits :: Const a b > Int Source # floatRange :: Const a b > (Int, Int) Source # decodeFloat :: Const a b > (Integer, Int) Source # encodeFloat :: Integer > Int > Const a b Source # exponent :: Const a b > Int Source # significand :: Const a b > Const a b Source # scaleFloat :: Int > Const a b > Const a b Source # isNaN :: Const a b > Bool Source # isInfinite :: Const a b > Bool Source # isDenormalized :: Const a b > Bool Source # isNegativeZero :: Const a b > Bool Source #  
Generic (Const a b)  
Ix a => Ix (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const  
Num a => Num (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const (+) :: Const a b > Const a b > Const a b Source # () :: Const a b > Const a b > Const a b Source # (*) :: Const a b > Const a b > Const a b Source # negate :: Const a b > Const a b Source # abs :: Const a b > Const a b Source # signum :: Const a b > Const a b Source # fromInteger :: Integer > Const a b Source #  
Read a => Read (Const a b)  This instance would be equivalent to the derived instances of the
Since: base4.8.0.0 
Fractional a => Fractional (Const a b)  Since: base4.9.0.0 
Integral a => Integral (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const quot :: Const a b > Const a b > Const a b Source # rem :: Const a b > Const a b > Const a b Source # div :: Const a b > Const a b > Const a b Source # mod :: Const a b > Const a b > Const a b Source # quotRem :: Const a b > Const a b > (Const a b, Const a b) Source # divMod :: Const a b > Const a b > (Const a b, Const a b) Source #  
Real a => Real (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const toRational :: Const a b > Rational Source #  
RealFrac a => RealFrac (Const a b)  Since: base4.9.0.0 
Show a => Show (Const a b)  This instance would be equivalent to the derived instances of the
Since: base4.8.0.0 
Eq a => Eq (Const a b)  Since: base4.9.0.0 
Ord a => Ord (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const  
type Rep1 (Const a :: k > Type)  Since: base4.9.0.0 
Defined in Data.Functor.Const  
type Rep (Const a b)  Since: base4.9.0.0 
Defined in Data.Functor.Const 
Lists, but with an Applicative
functor based on zipping.
ZipList  

Instances
Foldable ZipList  Since: base4.9.0.0 
Defined in Control.Applicative fold :: Monoid m => ZipList m > m Source # foldMap :: Monoid m => (a > m) > ZipList a > m Source # foldMap' :: Monoid m => (a > m) > ZipList a > m Source # foldr :: (a > b > b) > b > ZipList a > b Source # foldr' :: (a > b > b) > b > ZipList a > b Source # foldl :: (b > a > b) > b > ZipList a > b Source # foldl' :: (b > a > b) > b > ZipList a > b Source # foldr1 :: (a > a > a) > ZipList a > a Source # foldl1 :: (a > a > a) > ZipList a > a Source # toList :: ZipList a > [a] Source # null :: ZipList a > Bool Source # length :: ZipList a > Int Source # elem :: Eq a => a > ZipList a > Bool Source # maximum :: Ord a => ZipList a > a Source # minimum :: Ord a => ZipList a > a Source #  
Traversable ZipList  Since: base4.9.0.0 
Defined in Data.Traversable  
Alternative ZipList  Since: base4.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: base2.1 
Functor ZipList  Since: base2.1 
Generic1 ZipList  
Generic (ZipList a)  
IsList (ZipList a)  Since: base4.15.0.0 
Read a => Read (ZipList a)  Since: base4.7.0.0 
Show a => Show (ZipList a)  Since: base4.7.0.0 
Eq a => Eq (ZipList a)  Since: base4.7.0.0 
Ord a => Ord (ZipList a)  Since: base4.7.0.0 
Defined in Control.Applicative  
type Rep1 ZipList  Since: base4.7.0.0 
Defined in Control.Applicative  
type Rep (ZipList a)  Since: base4.7.0.0 
Defined in Control.Applicative  
type Item (ZipList a)  
Defined in GHC.IsList 
(<**>) :: Applicative f => f a > f (a > b) > f b infixl 4 Source #
A variant of <*>
with the arguments reversed.
liftA3 :: Applicative f => (a > b > c > d) > f a > f b > f c > f d Source #
Lift a ternary function to actions.
optional :: Alternative f => f a > f (Maybe a) Source #
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 *> final
Left "it failed">>>
runExcept $ optional canFail *> final
Right 42
(&&&) :: Arrow a => a b c > a b c' > a b (c, c') infixr 3 Source #
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 Source #
Lefttoright composition
(<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c > cat a b > cat a c infixr 1 Source #
Righttoleft composition
module Control.Concurrent.MVar
class (Typeable e, Show e) => Exception e Source #
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 MyException
The 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 = frontendExceptionFromException
We 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
Exception Void  Since: base4.8.0.0 
Defined in Data.Void toException :: Void > SomeException Source # fromException :: SomeException > Maybe Void Source # displayException :: Void > String Source #  
Exception ArithException  Since: base4.0.0.0 
Defined in GHC.Exception.Type  
Exception SomeException  Since: base3.0 
Defined in GHC.Exception.Type  
Exception UnicodeException  
Defined in Data.Text.Encoding.Error 
data SomeException Source #
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
.
Exception e => SomeException e 
Instances
Exception SomeException  Since: base3.0 
Defined in GHC.Exception.Type  
Show SomeException  Since: base3.0 
Defined in GHC.Exception.Type 
class (Alternative m, Monad m) => MonadPlus (m :: Type > Type) where Source #
Monads that also support choice and failure.
Nothing
The identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
mplus :: m a > m a > m a Source #
An associative operation. The default definition is
mplus = (<>
)
Instances
MonadPlus P  Since: base2.1 
MonadPlus ReadP  Since: base2.1 
MonadPlus Seq  
MonadPlus DList  
MonadPlus IO  Since: base4.9.0.0 
MonadPlus Maybe  Since: base2.1 
MonadPlus []  Since: base2.1 
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)  Since: base4.6.0.0 
Defined in Control.Arrow mzero :: ArrowMonad a a0 Source # mplus :: ArrowMonad a a0 > ArrowMonad a a0 > ArrowMonad a a0 Source #  
MonadPlus (Proxy :: Type > Type)  Since: base4.9.0.0 
MonadPlus (U1 :: Type > Type)  Since: base4.9.0.0 
MonadPlus m => MonadPlus (Kleisli m a)  Since: base4.14.0.0 
MonadPlus f => MonadPlus (Ap f)  Since: base4.12.0.0 
MonadPlus f => MonadPlus (Rec1 f)  Since: base4.9.0.0 
(MonadPlus f, MonadPlus g) => MonadPlus (Product f g)  Since: base4.9.0.0 
(MonadPlus f, MonadPlus g) => MonadPlus (f :*: g)  Since: base4.9.0.0 
MonadPlus f => MonadPlus (M1 i c f)  Since: base4.9.0.0 
class Applicative m => Monad (m :: Type > Type) where Source #
The Monad
class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do
expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad
should satisfy the following:
 Left identity
return
a>>=
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 lists, Maybe
and IO
defined in the Prelude satisfy these laws.
(>>=) :: m a > (a > m b) > m b infixl 1 Source #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
'as
' can be understood as the >>=
bsdo
expression
do a < as bs a
(>>) :: m a > m b > m b infixl 1 Source #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
'as
' can be understood as the >>
bsdo
expression
do as bs
Instances
Monad Complex  Since: base4.9.0.0 
Monad Identity  Since: base4.8.0.0 
Monad First  Since: base4.8.0.0 
Monad Last  Since: base4.8.0.0 
Monad Down  Since: base4.11.0.0 
Monad First  Since: base4.9.0.0 
Monad Last  Since: base4.9.0.0 
Monad Max  Since: base4.9.0.0 
Monad Min  Since: base4.9.0.0 
Monad Par1  Since: base4.9.0.0 
Monad P  Since: base2.1 
Monad ReadP  Since: base2.1 
Monad Seq  
Monad DList  
Monad IO  Since: base2.1 
Monad NonEmpty  Since: base4.9.0.0 
Monad Maybe  Since: base2.1 
Monad Solo  Since: base4.15 
Monad []  Since: base2.1 
Monad m => Monad (WrappedMonad m)  Since: base4.7.0.0 
Defined in Control.Applicative (>>=) :: WrappedMonad m a > (a > WrappedMonad m b) > WrappedMonad m b Source # (>>) :: WrappedMonad m a > WrappedMonad m b > WrappedMonad m b Source # return :: a > WrappedMonad m a Source #  
ArrowApply a => Monad (ArrowMonad a)  Since: base2.1 
Defined in Control.Arrow (>>=) :: ArrowMonad a a0 > (a0 > ArrowMonad a b) > ArrowMonad a b Source # (>>) :: ArrowMonad a a0 > ArrowMonad a b > ArrowMonad a b Source # return :: a0 > ArrowMonad a a0 Source #  
Monad (Either e)  Since: base4.4.0.0 
Monad (Proxy :: Type > Type)  Since: base4.7.0.0 
Monad (U1 :: Type > Type)  Since: base4.9.0.0 
Monoid a => Monad ((,) a)  Since: base4.9.0.0 
Monad m => Monad (Kleisli m a)  Since: base4.14.0.0 
Monad f => Monad (Ap f)  Since: base4.12.0.0 
Monad f => Monad (Rec1 f)  Since: base4.9.0.0 
(Applicative f, Monad f) => Monad (WhenMissing f x)  Equivalent to Since: containers0.5.9 
Defined in Data.IntMap.Internal (>>=) :: WhenMissing f x a > (a > WhenMissing f x b) > WhenMissing f x b Source # (>>) :: WhenMissing f x a > WhenMissing f x b > WhenMissing f x b Source # return :: a > WhenMissing f x a Source #  
(Monoid a, Monoid b) => Monad ((,,) a b)  Since: base4.14.0.0 
(Monad f, Monad g) => Monad (Product f g)  Since: base4.9.0.0 
(Monad f, Monad g) => Monad (f :*: g)  Since: base4.9.0.0 
(Monad f, Applicative f) => Monad (WhenMatched f x y)  Equivalent to Since: containers0.5.9 
Defined in Data.IntMap.Internal (>>=) :: WhenMatched f x y a > (a > WhenMatched f x y b) > WhenMatched f x y b Source # (>>) :: WhenMatched f x y a > WhenMatched f x y b > WhenMatched f x y b Source # return :: a > WhenMatched f x y a Source #  
(Applicative f, Monad f) => Monad (WhenMissing f k x)  Equivalent to Since: containers0.5.9 
Defined in Data.Map.Internal (>>=) :: WhenMissing f k x a > (a > WhenMissing f k x b) > WhenMissing f k x b Source # (>>) :: WhenMissing f k x a > WhenMissing f k x b > WhenMissing f k x b Source # return :: a > WhenMissing f k x a Source #  
(Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c)  Since: base4.14.0.0 
Monad ((>) r)  Since: base2.1 
Monad f => Monad (M1 i c f)  Since: base4.9.0.0 
(Monad f, Applicative f) => Monad (WhenMatched f k x y)  Equivalent to Since: containers0.5.9 
Defined in Data.Map.Internal (>>=) :: WhenMatched f k x y a > (a > WhenMatched f k x y b) > WhenMatched f k x y b Source # (>>) :: WhenMatched f k x y a > WhenMatched f k x y b > WhenMatched f k x y b Source # return :: a > WhenMatched f k x y a Source # 
forever :: Applicative f => f a > f b Source #
Repeat an action indefinitely.
Examples
A common use of forever
is to process input from network sockets,
Handle
s, 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 nonterminating.
If the action is in a
and shortcircuits after some number of iterations.
then MonadPlus
actually returns forever
mzero
, effectively shortcircuiting its caller.
guard :: Alternative f => Bool > f () Source #
Conditional failure of Alternative
computations. Defined by
guard True =pure
() guard False =empty
Examples
Common uses of guard
include conditionally signaling an error in
an error monad and conditionally rejecting the current choice in an
Alternative
based parser.
As an example of signaling 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 0
Nothing
>>>
safeDiv 4 2
Just 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 Source #
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
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
(=<<) :: Monad m => (a > m b) > m a > m b infixr 1 Source #
Same as >>=
, but with the arguments interchanged.
when :: Applicative f => Bool > f () > f () Source #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
filterM :: Applicative m => (a > m Bool) > [a] > m [a] Source #
This generalizes the listbased filter
function.
(>=>) :: Monad m => (a > m b) > (b > m c) > a > m c infixr 1 Source #
Lefttoright composition of Kleisli arrows.
'(bs
' can be understood as the >=>
cs) ado
expression
do b < bs a cs b
zipWithM :: Applicative m => (a > b > m c) > [a] > [b] > m [c] Source #
zipWithM_ :: Applicative m => (a > b > m c) > [a] > [b] > m () Source #
replicateM :: Applicative m => Int > m a > m [a] Source #
performs the action replicateM
n actact
n
times,
and then returns the list of results:
Examples
>>>
import Control.Monad.State
>>>
runState (replicateM 3 $ state $ \s > (s, s + 1)) 1
([1,2,3],4)
replicateM_ :: Applicative m => Int > m a > m () Source #
(<$!>) :: Monad m => (a > b) > m a > m b infixl 4 Source #
Strict version of <$>
.
Since: base4.8.0.0
class Monad m => MonadFail (m :: Type > Type) where Source #
When a value is bound in do
notation, the pattern on the left
hand side of <
might not match. In this case, this class
provides a function to recover.
A Monad
without a MonadFail
instance may only be used in conjunction
with pattern that always match, such as newtypes, tuples, data types with
only a single data constructor, and irrefutable patterns (~pat
).
Instances of MonadFail
should satisfy the following law: fail s
should
be a left zero for >>=
,
fail s >>= f = fail s
If your Monad
is also MonadPlus
, a popular definition is
fail _ = mzero
Since: base4.9.0.0
Instances
MonadFail P  Since: base4.9.0.0 
Defined in Text.ParserCombinators.ReadP  
MonadFail ReadP  Since: base4.9.0.0 
MonadFail DList  
MonadFail IO  Since: base4.9.0.0 
MonadFail Maybe  Since: base4.9.0.0 
MonadFail []  Since: base4.9.0.0 
Defined in Control.Monad.Fail  
MonadFail f => MonadFail (Ap f)  Since: base4.12.0.0 
module Control.Monad.IO.Class
class Bifunctor (p :: Type > Type > Type) where Source #
A bifunctor is a type constructor that takes
two type arguments and is a functor in both arguments. That
is, unlike with Functor
, a type constructor such as Either
does not need to be partially applied for a Bifunctor
instance, and the methods in this class permit mapping
functions over the Left
value or the Right
value,
or both at the same time.
Formally, the class Bifunctor
represents a bifunctor
from Hask
> Hask
.
Intuitively it is a bifunctor where both the first and second arguments are covariant.
You can define a Bifunctor
by either defining bimap
or by
defining both first
and second
.
If you supply bimap
, you should ensure that:
bimap
id
id
≡id
If you supply first
and second
, ensure:
first
id
≡id
second
id
≡id
If you supply both, you should also ensure:
bimap
f g ≡first
f.
second
g
These ensure by parametricity:
bimap
(f.
g) (h.
i) ≡bimap
f h.
bimap
g ifirst
(f.
g) ≡first
f.
first
gsecond
(f.
g) ≡second
f.
second
g
Since: base4.8.0.0
bimap :: (a > b) > (c > d) > p a c > p b d Source #
Map over both arguments at the same time.
bimap
f g ≡first
f.
second
g
Examples
>>>
bimap toUpper (+1) ('j', 3)
('J',4)
>>>
bimap toUpper (+1) (Left 'j')
Left 'J'
>>>
bimap toUpper (+1) (Right 3)
Right 4
Instances
Bifunctor Either  Since: base4.8.0.0 
Bifunctor Arg  Since: base4.9.0.0 
Bifunctor (,)  Since: base4.8.0.0 
Bifunctor (Const :: Type > Type > Type)  Since: base4.8.0.0 
Bifunctor ((,,) x1)  Since: base4.8.0.0 
Bifunctor (K1 i :: Type > Type > Type)  Since: base4.9.0.0 
Bifunctor ((,,,) x1 x2)  Since: base4.8.0.0 
Bifunctor ((,,,,) x1 x2 x3)  Since: base4.8.0.0 
Bifunctor ((,,,,,) x1 x2 x3 x4)  Since: base4.8.0.0 
Bifunctor ((,,,,,,) x1 x2 x3 x4 x5)  Since: base4.8.0.0 
toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a > Maybe b Source #
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 x
This 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: base4.8.0.0
Instances
bool :: a > a > Bool > a Source #
Case analysis for the Bool
type.
evaluates to bool
x y px
when p
is False
, and evaluates to y
when p
is True
.
This is equivalent to if p then y else x
; that is, one can
think of it as an ifthenelse construct with its arguments
reordered.
Examples
Basic usage:
>>>
bool "foo" "bar" True
"bar">>>
bool "foo" "bar" False
"foo"
Confirm that
and bool
x y pif p then y else x
are
equivalent:
>>>
let p = True; x = "bar"; y = "foo"
>>>
bool x y p == if p then y else x
True>>>
let p = False
>>>
bool x y p == if p then y else x
True
Since: base4.7.0.0
The character type Char
is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) code points (i.e. characters, see
http://www.unicode.org/ for details). This set extends the ISO 88591
(Latin1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char
.
To convert a Char
to or from the corresponding Int
value defined
by Unicode, use toEnum
and fromEnum
from the
Enum
class respectively (or equivalently ord
and
chr
).
Instances
Bounded Char  Since: base2.1 
Enum Char  Since: base2.1 
Read Char  Since: base2.1 
Show Char  Since: base2.1 
Eq Char  
Ord Char  
ToLText String Source #  
ToString String Source #  
ToText String Source #  
ConvertUtf8 String ByteString Source #  
Defined in Incipit.String.Conversion encodeUtf8 :: String > ByteString Source # decodeUtf8 :: ByteString > String Source # decodeUtf8Strict :: ByteString > Either UnicodeException String Source #  
ConvertUtf8 String ShortByteString Source #  Since: 0.6.0.0 
Defined in Incipit.String.Conversion  
ConvertUtf8 String LByteString Source #  Converting 
Defined in Incipit.String.Conversion  
Generic1 (URec Char :: k > Type)  
Foldable (UChar :: Type > Type)  Since: base4.9.0.0 
Defined in Data.Foldable fold :: Monoid m => UChar m > m Source # foldMap :: Monoid m => (a > m) > UChar a > m Source # foldMap' :: Monoid m => (a > m) > UChar a > m Source # foldr :: (a > b > b) > b > UChar a > b Source # foldr' :: (a > b > b) > b > UChar a > b Source # foldl :: (b > a > b) > b > UChar a > b Source # foldl' :: (b > a > b) > b > UChar a > b Source # foldr1 :: (a > a > a) > UChar a > a Source # foldl1 :: (a > a > a) > UChar a > a Source # toList :: UChar a > [a] Source # null :: UChar a > Bool Source # length :: UChar a > Int Source # elem :: Eq a => a > UChar a > Bool Source # maximum :: Ord a => UChar a > a Source # minimum :: Ord a => UChar a > a Source #  
Traversable (UChar :: Type > Type)  Since: base4.9.0.0 
Functor (URec Char :: Type > Type)  Since: base4.9.0.0 
Generic (URec Char p)  
Show (URec Char p)  Since: base4.9.0.0 
Eq (URec Char p)  Since: base4.9.0.0 
Ord (URec Char p)  Since: base4.9.0.0 
Defined in GHC.Generics compare :: URec Char p > URec Char p > Ordering Source # (<) :: URec Char p > URec Char p > Bool Source # (<=) :: URec Char p > URec Char p > Bool Source # (>) :: URec Char p > URec Char p > Bool Source # (>=) :: URec Char p > URec Char p > Bool Source #  
data URec Char (p :: k)  Used for marking occurrences of Since: base4.9.0.0 
type Compare (a :: Char) (b :: Char)  
Defined in Data.Type.Ord  
type Rep1 (URec Char :: k > Type)  Since: base4.9.0.0 
Defined in GHC.Generics  
type Rep (URec Char p)  Since: base4.9.0.0 
Defined in GHC.Generics 
class a ~R# b => Coercible (a :: k) (b :: k) Source #
Coercible
is a twoparameter class that has instances for types a
and b
if
the compiler can infer that they have the same representation. This class
does not have regular instances; instead they are created onthefly during
typechecking. Trying to manually declare an instance of Coercible
is an error.
Nevertheless one can pretend that the following three kinds of instances exist. First, as a trivial basecase:
instance Coercible a a
Furthermore, for every type constructor there is
an instance that allows to coerce under the type constructor. For
example, let D
be a prototypical type constructor (data
or
newtype
) with three type arguments, which have roles nominal
,
representational
resp. phantom
. Then there is an instance of
the form
instance Coercible b b' => Coercible (D a b c) (D a b' c')
Note that the nominal
type arguments are equal, the
representational
type arguments can differ, but need to have a
Coercible
instance themself, and the phantom
type arguments can be
changed arbitrarily.
The third kind of instance exists for every newtype NT = MkNT T
and
comes in two variants, namely
instance Coercible a T => Coercible a NT
instance Coercible T b => Coercible NT b
This instance is only usable if the constructor MkNT
is in scope.
If, as a library author of a type constructor like Set a
, you
want to prevent a user of your module to write
coerce :: Set T > Set NT
,
you need to set the role of Set
's type parameter to nominal
,
by writing
type role Set nominal
For more details about this feature, please refer to Safe Coercions by Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones and Stephanie Weirich.
Since: ghcprim0.4.0
coerce :: forall {k :: RuntimeRep} (a :: TYPE k) (b :: TYPE k). Coercible a b => a > b Source #
The function coerce
allows you to safely convert between values of
types that have the same representation with no runtime overhead. In the
simplest case you can use it instead of a newtype constructor, to go from
the newtype's concrete type to the abstract type. But it also works in
more complicated settings, e.g. converting a list of newtypes to a list of
concrete types.
This function is representationpolymorphic, but the
RuntimeRep
type argument is marked as Inferred
, meaning
that it is not available for visible type application. This means
the typechecker will accept coerce @Int @Age 42
.
module Data.Either
The Eq
class defines equality (==
) and inequality (/=
).
All the basic datatypes exported by the Prelude are instances of Eq
,
and Eq
may be derived for any datatype whose constituents are also
instances of Eq
.
The Haskell Report defines no laws for Eq
. However, instances are
encouraged to follow these properties:
Instances
Eq SomeTypeRep  
Defined in Data.Typeable.Internal (==) :: SomeTypeRep > SomeTypeRep > Bool Source # (/=) :: SomeTypeRep > SomeTypeRep > Bool Source #  
Eq Void  Since: base4.8.0.0 
Eq ArithException  Since: base3.0 
Defined in GHC.Exception.Type (==) :: ArithException > ArithException > Bool Source # (/=) :: ArithException > ArithException > Bool Source #  
Eq Associativity  Since: base4.6.0.0 
Defined in GHC.Generics (==) :: Associativity > Associativity > Bool Source # (/=) :: Associativity > Associativity > Bool Source #  
Eq DecidedStrictness  Since: base4.9.0.0 
Defined in GHC.Generics (==) :: DecidedStrictness > DecidedStrictness > Bool Source # (/=) :: DecidedStrictness > DecidedStrictness > Bool Source #  
Eq Fixity  Since: base4.6.0.0 
Eq SourceStrictness  Since: base4.9.0.0 
Defined in GHC.Generics (==) :: SourceStrictness > SourceStrictness > Bool Source # (/=) :: SourceStrictness > SourceStrictness > Bool Source #  
Eq SourceUnpackedness  Since: base4.9.0.0 
Defined in GHC.Generics (==) :: SourceUnpackedness > SourceUnpackedness > Bool Source # (/=) :: SourceUnpackedness > SourceUnpackedness > Bool Source #  
Eq MaskingState  Since: base4.3.0.0 
Defined in GHC.IO (==) :: MaskingState > MaskingState > Bool Source # (/=) :: MaskingState > MaskingState > Bool Source #  
Eq Int16  Since: base2.1 
Eq Int32  Since: base2.1 
Eq Int64  Since: base2.1 
Eq Int8  Since: base2.1 
Eq SrcLoc  Since: base4.9.0.0 
Eq SomeChar  
Eq SomeSymbol  Since: base4.7.0.0 
Defined in GHC.TypeLits (==) :: SomeSymbol > SomeSymbol > Bool Source # (/=) :: SomeSymbol > SomeSymbol > Bool Source #  
Eq SomeNat  Since: base4.7.0.0 
Eq Word16  Since: base2.1 
Eq Word32  Since: base2.1 
Eq Word64  Since: base2.1 
Eq Word8  Since: base2.1 
Eq ByteString  
Defined in Data.ByteString.Internal.Type (==) :: ByteString > ByteString > Bool Source # (/=) :: ByteString > ByteString > Bool Source #  
Eq ByteString  
Defined in Data.ByteString.Lazy.Internal (==) :: ByteString > ByteString > Bool Source # (/=) :: ByteString > ByteString > Bool Source #  
Eq ShortByteString  
Defined in Data.ByteString.Short.Internal (==) :: ShortByteString > ShortByteString > Bool Source # (/=) :: ShortByteString > ShortByteString > Bool Source #  
Eq IntSet  
Eq BigNat  
Eq Module  
Eq Ordering  
Eq TrName  
Eq TyCon  
Eq UnicodeException  
Defined in Data.Text.Encoding.Error (==) :: UnicodeException > UnicodeException > Bool Source # (/=) :: UnicodeException > UnicodeException > Bool Source #  
Eq Integer  
Eq Natural  
Eq ()  
Eq Bool  
Eq Char  
Eq Double  Note that due to the presence of
Also note that

Eq Float  Note that due to the presence of
Also note that

Eq Int  
Eq Word  
Eq a => Eq (ZipList a)  Since: base4.7.0.0 
Eq a => Eq (And a)  Since: base4.16 
Eq a => Eq (Iff a)  Since: base4.16 
Eq a => Eq (Ior a)  Since: base4.16 
Eq a => Eq (Xor a)  Since: base4.16 
Eq a => Eq (Complex a)  Since: base2.1 
Eq a => Eq (Identity a)  Since: base4.8.0.0 
Eq a => Eq (First a)  Since: base2.1 
Eq a => Eq (Last a)  Since: base2.1 
Eq a => Eq (Down a)  Since: base4.6.0.0 
Eq a => Eq (First a)  Since: base4.9.0.0 
Eq a => Eq (Last a)  Since: base4.9.0.0 
Eq a => Eq (Max a)  Since: base4.9.0.0 
Eq a => Eq (Min a)  Since: base4.9.0.0 
Eq m => Eq (WrappedMonoid m)  Since: base4.9.0.0 
Defined in Data.Semigroup (==) :: WrappedMonoid m > WrappedMonoid m > Bool Source # (/=) :: WrappedMonoid m > WrappedMonoid m > Bool Source #  
Eq p => Eq (Par1 p)  Since: base4.7.0.0 
Eq (MVar a)  Since: base4.1.0.0 
Eq a => Eq (Ratio a)  Since: base2.1 
Eq a => Eq (IntMap a)  
Eq a => Eq (Seq a)  
Eq a => Eq (ViewL a)  
Eq a => Eq (ViewR a)  
Eq a => Eq (Intersection a)  
Defined in Data.Set.Internal (==) :: Intersection a > Intersection a > Bool Source # (/=) :: Intersection a > Intersection a > Bool Source #  
Eq a => Eq (Set a)  
Eq a => Eq (DList a)  
Eq a => Eq (NonEmpty a)  Since: base4.9.0.0 
Eq a => Eq (Maybe a)  Since: base2.1 
Eq a => Eq (a)  
Eq a => Eq [a]  
(Eq a, Eq b) => Eq (Either a b)  Since: base2.1 
Eq (Fixed a)  Since: base2.1 
Eq (Proxy s)  Since: base4.7.0.0 
Eq a => Eq (Arg a b)  Since: base4.9.0.0 
Eq (TypeRep a)  Since: base2.1 
Eq (U1 p)  Since: base4.9.0.0 
Eq (V1 p)  Since: base4.9.0.0 
(Eq k, Eq a) => Eq (Map k a)  
(Eq a, Eq b) => Eq (a, b)  
Eq a => Eq (Const a b)  Since: base4.9.0.0 
Eq (f a) => Eq (Ap f a)  Since: base4.12.0.0 
Eq (a :~: b)  Since: base4.7.0.0 
Eq (OrderingI a b)  
Eq (f p) => Eq (Rec1 f p)  Since: base4.7.0.0 
Eq (URec (Ptr ()) p)  Since: base4.9.0.0 
Eq (URec Char p)  Since: base4.9.0.0 
Eq (URec Double p)  Since: base4.9.0.0 
Eq (URec Float p)  
Eq (URec Int p)  Since: base4.9.0.0 
Eq (URec Word p)  Since: base4.9.0.0 
(Eq a, Eq b, Eq c) => Eq (a, b, c)  
(Eq1 f, Eq1 g, Eq a) => Eq (Product f g a)  Since: base4.9.0.0 
(Eq1 f, Eq1 g, Eq a) => Eq (Sum f g a)  Since: base4.9.0.0 
Eq (a :~~: b)  Since: base4.10.0.0 
(Eq (f p), Eq (g p)) => Eq ((f :*: g) p)  Since: base4.7.0.0 
(Eq (f p), Eq (g p)) => Eq ((f :+: g) p)  Since: base4.7.0.0 
Eq c => Eq (K1 i c p)  Since: base4.7.0.0 
(Eq a, Eq b, Eq c, Eq d) => Eq (a, b, c, d)  