Copyright | (c) 2021 Tony Zorman |
---|---|
License | BSD3-style (see LICENSE) |
Maintainer | Tony Zorman <soliditsallgood@mailbox.org> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Utility functions and re-exports for a more ergonomic developing experience. Users themselves will not find much use here.
Synopsis
- (++) :: [a] -> [a] -> [a]
- filter :: (a -> Bool) -> [a] -> [a]
- zip :: [a] -> [b] -> [(a, b)]
- otherwise :: Bool
- map :: (a -> b) -> [a] -> [b]
- ($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b
- guard :: Alternative f => Bool -> f ()
- join :: Monad m => m (m a) -> m a
- class Applicative m => Monad (m :: Type -> Type) where
- class Functor (f :: Type -> Type) where
- class Monad m => MonadFail (m :: Type -> Type) where
- class Functor f => Applicative (f :: Type -> Type) where
- class Foldable (t :: TYPE LiftedRep -> Type) where
- fold :: Monoid m => t m -> m
- foldMap :: Monoid m => (a -> m) -> t a -> m
- foldMap' :: Monoid m => (a -> m) -> t a -> m
- foldr :: (a -> b -> b) -> b -> t a -> b
- foldr' :: (a -> b -> b) -> b -> t a -> b
- foldl :: (b -> a -> b) -> b -> t a -> b
- foldl' :: (b -> a -> b) -> b -> t a -> b
- foldr1 :: (a -> a -> a) -> t a -> a
- foldl1 :: (a -> a -> a) -> t a -> a
- null :: t a -> Bool
- length :: t a -> Int
- elem :: Eq a => a -> t a -> Bool
- maximum :: Ord a => t a -> a
- minimum :: Ord a => t a -> a
- sum :: Num a => t a -> a
- product :: Num a => t a -> a
- 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)
- (<>) :: Semigroup a => a -> a -> a
- class Semigroup a => Monoid a where
- data Bool
- data Char
- data Maybe a
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- unless :: Applicative f => Bool -> f () -> f ()
- replicateM_ :: Applicative m => Int -> m a -> m ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- forever :: Applicative f => f a -> f b
- foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- 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
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- isSubsequenceOf :: Eq a => [a] -> [a] -> Bool
- mapAccumR :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)
- mapAccumL :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)
- foldMapDefault :: (Traversable t, Monoid m) => (a -> m) -> t a -> m
- fmapDefault :: Traversable t => (a -> b) -> t a -> t b
- newtype ZipList a = ZipList {
- getZipList :: [a]
- newtype WrappedMonad (m :: Type -> Type) a = WrapMonad {
- unwrapMonad :: m a
- newtype WrappedArrow (a :: Type -> Type -> Type) b c = WrapArrow {
- unwrapArrow :: a b c
- optional :: Alternative f => f a -> f (Maybe a)
- newtype Const a (b :: k) = Const {
- getConst :: a
- traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f ()
- or :: Foldable t => t Bool -> Bool
- notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
- minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b
- foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- find :: Foldable t => (a -> Bool) -> t a -> Maybe a
- concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- concat :: Foldable t => t [a] -> [a]
- asum :: (Foldable t, Alternative f) => t (f a) -> f a
- any :: Foldable t => (a -> Bool) -> t a -> Bool
- and :: Foldable t => t Bool -> Bool
- all :: Foldable t => (a -> Bool) -> t a -> Bool
- zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
- zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
- zipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
- zipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
- zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]
- zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]
- zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]
- zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]
- words :: String -> [String]
- unzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])
- unzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])
- unzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])
- unzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])
- unwords :: [String] -> String
- unlines :: [String] -> String
- unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- union :: Eq a => [a] -> [a] -> [a]
- unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
- transpose :: [[a]] -> [[a]]
- tails :: [a] -> [[a]]
- subsequences :: [a] -> [[a]]
- stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- sort :: Ord a => [a] -> [a]
- singleton :: a -> [a]
- permutations :: [a] -> [[a]]
- partition :: (a -> Bool) -> [a] -> ([a], [a])
- nubBy :: (a -> a -> Bool) -> [a] -> [a]
- nub :: Eq a => [a] -> [a]
- lines :: String -> [String]
- isSuffixOf :: Eq a => [a] -> [a] -> Bool
- isPrefixOf :: Eq a => [a] -> [a] -> Bool
- isInfixOf :: Eq a => [a] -> [a] -> Bool
- intersperse :: a -> [a] -> [a]
- intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- intersect :: Eq a => [a] -> [a] -> [a]
- intercalate :: [a] -> [[a]] -> [a]
- insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
- insert :: Ord a => a -> [a] -> [a]
- inits :: [a] -> [[a]]
- groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
- group :: Eq a => [a] -> [[a]]
- genericTake :: Integral i => i -> [a] -> [a]
- genericSplitAt :: Integral i => i -> [a] -> ([a], [a])
- genericReplicate :: Integral i => i -> a -> [a]
- genericLength :: Num i => [a] -> i
- genericIndex :: Integral i => [a] -> i -> a
- genericDrop :: Integral i => i -> [a] -> [a]
- findIndices :: (a -> Bool) -> [a] -> [Int]
- findIndex :: (a -> Bool) -> [a] -> Maybe Int
- elemIndices :: Eq a => a -> [a] -> [Int]
- elemIndex :: Eq a => a -> [a] -> Maybe Int
- dropWhileEnd :: (a -> Bool) -> [a] -> [a]
- deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
- delete :: Eq a => a -> [a] -> [a]
- (\\) :: Eq a => [a] -> [a] -> [a]
- newtype Last a = Last {}
- newtype First a = First {}
- newtype Ap (f :: k -> Type) (a :: k) = Ap {
- getAp :: f a
- newtype Sum a = Sum {
- getSum :: a
- newtype Product a = Product {
- getProduct :: a
- newtype Endo a = Endo {
- appEndo :: a -> a
- newtype Dual a = Dual {
- getDual :: a
- newtype Any = Any {}
- newtype Alt (f :: k -> Type) (a :: k) = Alt {
- getAlt :: f a
- newtype All = All {}
- isSeparator :: Char -> Bool
- isNumber :: Char -> Bool
- isMark :: Char -> Bool
- isLetter :: Char -> Bool
- digitToInt :: Char -> Int
- readLitChar :: ReadS Char
- lexLitChar :: ReadS String
- data GeneralCategory
- = UppercaseLetter
- | LowercaseLetter
- | TitlecaseLetter
- | ModifierLetter
- | OtherLetter
- | NonSpacingMark
- | SpacingCombiningMark
- | EnclosingMark
- | DecimalNumber
- | LetterNumber
- | OtherNumber
- | ConnectorPunctuation
- | DashPunctuation
- | OpenPunctuation
- | ClosePunctuation
- | InitialQuote
- | FinalQuote
- | OtherPunctuation
- | MathSymbol
- | CurrencySymbol
- | ModifierSymbol
- | OtherSymbol
- | Space
- | LineSeparator
- | ParagraphSeparator
- | Control
- | Format
- | Surrogate
- | PrivateUse
- | NotAssigned
- toUpper :: Char -> Char
- toTitle :: Char -> Char
- toLower :: Char -> Char
- isUpper :: Char -> Bool
- isSymbol :: Char -> Bool
- isSpace :: Char -> Bool
- isPunctuation :: Char -> Bool
- isPrint :: Char -> Bool
- isOctDigit :: Char -> Bool
- isLower :: Char -> Bool
- isLatin1 :: Char -> Bool
- isHexDigit :: Char -> Bool
- isDigit :: Char -> Bool
- isControl :: Char -> Bool
- isAsciiUpper :: Char -> Bool
- isAsciiLower :: Char -> Bool
- isAscii :: Char -> Bool
- isAlphaNum :: Char -> Bool
- isAlpha :: Char -> Bool
- generalCategory :: Char -> GeneralCategory
- chr :: Int -> Char
- showLitChar :: Char -> ShowS
- intToDigit :: Int -> Char
- zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- unzip :: [(a, b)] -> ([a], [b])
- uncons :: [a] -> Maybe (a, [a])
- takeWhile :: (a -> Bool) -> [a] -> [a]
- take :: Int -> [a] -> [a]
- tail :: [a] -> [a]
- splitAt :: Int -> [a] -> ([a], [a])
- span :: (a -> Bool) -> [a] -> ([a], [a])
- scanr1 :: (a -> a -> a) -> [a] -> [a]
- scanr :: (a -> b -> b) -> b -> [a] -> [b]
- scanl1 :: (a -> a -> a) -> [a] -> [a]
- scanl' :: (b -> a -> b) -> b -> [a] -> [b]
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
- reverse :: [a] -> [a]
- replicate :: Int -> a -> [a]
- repeat :: a -> [a]
- lookup :: Eq a => a -> [(a, b)] -> Maybe b
- last :: [a] -> a
- iterate' :: (a -> a) -> a -> [a]
- iterate :: (a -> a) -> a -> [a]
- init :: [a] -> [a]
- head :: [a] -> a
- foldl1' :: (a -> a -> a) -> [a] -> a
- dropWhile :: (a -> Bool) -> [a] -> [a]
- drop :: Int -> [a] -> [a]
- cycle :: [a] -> [a]
- break :: (a -> Bool) -> [a] -> ([a], [a])
- (!!) :: [a] -> Int -> a
- maybeToList :: Maybe a -> [a]
- maybe :: b -> (a -> b) -> Maybe a -> b
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- listToMaybe :: [a] -> Maybe a
- isNothing :: Maybe a -> Bool
- isJust :: Maybe a -> Bool
- fromMaybe :: a -> Maybe a -> a
- fromJust :: HasCallStack => Maybe a -> a
- catMaybes :: [Maybe a] -> [a]
- bool :: a -> a -> Bool -> a
- on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
- fix :: (a -> a) -> a
- (&) :: a -> (a -> b) -> b
- void :: Functor f => f a -> f ()
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- ($>) :: Functor f => f a -> b -> f b
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- class Applicative f => Alternative (f :: Type -> Type) where
- when :: Applicative f => Bool -> f () -> f ()
- ord :: Char -> Int
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- liftA :: Applicative f => (a -> b) -> f a -> f b
- id :: a -> a
- flip :: (a -> b -> c) -> b -> a -> c
- const :: a -> b -> a
- ap :: Monad m => m (a -> b) -> m a -> m b
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- (.) :: (b -> c) -> (a -> b) -> a -> c
- (&&) :: Bool -> Bool -> Bool
- not :: Bool -> Bool
- (||) :: Bool -> Bool -> Bool
- fi :: (Integral a, Num b) => a -> b
- chunksOf :: Int -> [a] -> [[a]]
- (.:) :: (a -> b) -> (c -> d -> a) -> c -> d -> b
- (!?) :: [a] -> Int -> Maybe a
- data NonEmpty a = a :| [a]
- notEmpty :: HasCallStack => [a] -> NonEmpty a
- safeGetWindowAttributes :: Window -> X (Maybe WindowAttributes)
- mkAbsolutePath :: MonadIO m => FilePath -> m FilePath
- findM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a)
- keyToString :: (KeyMask, KeySym) -> String
- keymaskToString :: KeyMask -> KeyMask -> String
- cleanKeyMask :: X (KeyMask -> KeyMask)
- regularKeys :: [(String, KeySym)]
- allSpecialKeys :: [(String, KeySym)]
- specialKeys :: [(String, KeySym)]
- multimediaKeys :: [(String, KeySym)]
- functionKeys :: [(String, KeySym)]
- type WindowScreen = Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
- data Stream a = !a :~ (Stream a)
- (+~) :: [a] -> Stream a -> Stream a
- cycleS :: NonEmpty a -> Stream a
- takeS :: Int -> Stream a -> [a]
- toList :: IsList l => l -> [Item l]
- fromList :: IsList l => [Item l] -> l
Documentation
(++) :: [a] -> [a] -> [a] infixr 5 #
Append two lists, i.e.,
[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn] [x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]
If the first list is not finite, the result is the first list.
filter :: (a -> Bool) -> [a] -> [a] #
\(\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]
>>>
filter odd [1, 2, 3]
[1,3]
zip :: [a] -> [b] -> [(a, b)] #
\(\mathcal{O}(\min(m,n))\). zip
takes two lists and returns a list of
corresponding pairs.
>>>
zip [1, 2] ['a', 'b']
[(1,'a'),(2,'b')]
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..] []
[]
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.
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, ...]
>>>
map (+1) [1, 2, 3]
[2,3,4]
($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b infixr 0 #
Application operator. This operator is redundant, since ordinary
application (f x)
means the same as (f
. However, $
x)$
has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:
f $ g $ h x = f (g (h x))
It is also useful in higher-order situations, such as
,
or map
($
0) xs
.zipWith
($
) fs xs
Note that (
is levity-polymorphic in its result type, so that
$
)foo
where $
Truefoo :: Bool -> Int#
is well-typed.
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 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 #
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
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
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 #
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 #
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
Inject a value into the monadic type.
Instances
Monad Complex | Since: base-4.9.0.0 |
Monad Identity | Since: base-4.8.0.0 |
Monad First | Since: base-4.8.0.0 |
Monad Last | Since: base-4.8.0.0 |
Monad Down | Since: base-4.11.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 Dual | Since: base-4.8.0.0 |
Monad Product | Since: base-4.8.0.0 |
Monad Sum | Since: base-4.8.0.0 |
Monad STM | Since: base-4.3.0.0 |
Monad Par1 | Since: base-4.9.0.0 |
Monad P | Since: base-2.1 |
Monad ReadP | Since: base-2.1 |
Monad ReadPrec | Since: base-2.1 |
Monad Seq | |
Monad Tree | |
Monad IO | Since: base-2.1 |
Monad Q | |
Monad Query | |
Monad X | |
Monad FocusQuery Source # | |
Defined in XMonad.Hooks.Focus (>>=) :: FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b # (>>) :: FocusQuery a -> FocusQuery b -> FocusQuery b # return :: a -> FocusQuery a # | |
Monad Parser Source # | |
Monad PureX Source # | |
Monad NonEmpty | Since: base-4.9.0.0 |
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 (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # return :: a -> WrappedMonad m a # | |
ArrowApply a => Monad (ArrowMonad a) | Since: base-2.1 |
Defined in Control.Arrow (>>=) :: 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 m => Monad (ListT m) | |
Monad m => Monad (MaybeT m) | |
Monad (TwoD a) Source # | |
Monad m => Monad (Invisible m) Source # | |
Monad (StateQuery s) Source # | |
Defined in XMonad.Util.WindowState (>>=) :: StateQuery s a -> (a -> StateQuery s b) -> StateQuery s b # (>>) :: StateQuery s a -> StateQuery s b -> StateQuery s b # return :: a -> StateQuery s a # | |
Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
Monad m => Monad (Kleisli m a) | Since: base-4.14.0.0 |
Monad f => Monad (Ap f) | Since: base-4.12.0.0 |
Monad f => Monad (Alt f) | Since: base-4.8.0.0 |
Monad f => Monad (Rec1 f) | 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 (>>=) :: 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, Error e) => Monad (ErrorT e m) | |
Monad m => Monad (ExceptT e m) | |
Monad m => Monad (IdentityT m) | |
Monad m => Monad (ReaderT r m) | |
Monad m => Monad (StateT s m) | |
Monad m => Monad (StateT s m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
(Monoid w, Monad m) => Monad (WriterT w m) | |
(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, Monad g) => Monad (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 (>>=) :: 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 (>>=) :: 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 (ContT r m) | |
(Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
Monad ((->) r) | Since: base-2.1 |
Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
(Monad f, Applicative f) => Monad (WhenMatched f k x y) | Equivalent to Since: containers-0.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 # (>>) :: 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 # | |
(Monoid w, Monad m) => Monad (RWST r w s m) | |
(Monoid w, Monad m) => Monad (RWST r w s m) | |
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.
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 Nothing
Nothing>>>
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 ZipList | Since: base-2.1 |
Functor Handler | Since: base-4.6.0.0 |
Functor Complex | Since: base-4.9.0.0 |
Functor Identity | Since: base-4.8.0.0 |
Functor First | Since: base-4.8.0.0 |
Functor Last | Since: base-4.8.0.0 |
Functor Down | Since: base-4.11.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 Dual | Since: base-4.8.0.0 |
Functor Product | Since: base-4.8.0.0 |
Functor Sum | Since: base-4.8.0.0 |
Functor STM | Since: base-4.3.0.0 |
Functor Par1 | Since: base-4.9.0.0 |
Functor P | Since: base-4.8.0.0 |
Defined in Text.ParserCombinators.ReadP | |
Functor ReadP | Since: base-2.1 |
Functor ReadPrec | Since: base-2.1 |
Functor IntMap | |
Functor Digit | |
Functor Elem | |
Functor FingerTree | |
Defined in Data.Sequence.Internal fmap :: (a -> b) -> FingerTree a -> FingerTree b # (<$) :: a -> FingerTree b -> FingerTree a # | |
Functor Node | |
Functor Seq | |
Functor ViewL | |
Functor ViewR | |
Functor Tree | |
Functor IO | Since: base-2.1 |
Functor Q | |
Functor TyVarBndr | |
Functor Directories' | |
Defined in XMonad.Core fmap :: (a -> b) -> Directories' a -> Directories' b # (<$) :: a -> Directories' b -> Directories' a # | |
Functor Query | |
Functor X | |
Functor Stack | |
Functor Cursors Source # | |
Functor FocusQuery Source # | |
Defined in XMonad.Hooks.Focus fmap :: (a -> b) -> FocusQuery a -> FocusQuery b # (<$) :: a -> FocusQuery b -> FocusQuery a # | |
Functor Stream Source # | |
Functor Parser Source # | |
Functor PureX Source # | |
Functor NonEmpty | Since: base-4.9.0.0 |
Functor Maybe | Since: base-2.1 |
Functor Solo | Since: base-4.15 |
Functor [] | Since: base-2.1 |
Monad m => Functor (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative fmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b # (<$) :: a -> WrappedMonad m b -> WrappedMonad m a # | |
Arrow a => Functor (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # (<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
Functor (Either a) | Since: base-3.0 |
Functor (StateL s) | Since: base-4.0 |
Defined in Data.Functor.Utils | |
Functor (StateR s) | Since: base-4.0 |
Defined in Data.Functor.Utils | |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Arg a) | Since: base-4.9.0.0 |
Functor (Array i) | Since: base-2.1 |
Functor (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Functor (V1 :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Functor (Map k) | |
Functor m => Functor (ListT m) | |
Functor m => Functor (MaybeT m) | |
Functor (TwoD a) Source # | |
Functor (History k) Source # | |
Functor m => Functor (Invisible m) Source # | |
Functor (StateQuery s) Source # | |
Defined in XMonad.Util.WindowState fmap :: (a -> b) -> StateQuery s a -> StateQuery s b # (<$) :: a -> StateQuery s b -> StateQuery s a # | |
Functor ((,) a) | Since: base-2.1 |
Arrow a => Functor (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
Functor m => Functor (Kleisli m a) | Since: base-4.14.0.0 |
Functor (Const m :: Type -> Type) | Since: base-2.1 |
Functor f => Functor (Ap f) | Since: base-4.12.0.0 |
Functor f => Functor (Alt f) | Since: base-4.8.0.0 |
Functor f => Functor (Rec1 f) | Since: base-4.9.0.0 |
Functor (URec (Ptr ()) :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Functor (URec Char :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Functor (URec Double :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Functor (URec Float :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Functor (URec Int :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Functor (URec Word :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
(Applicative f, Monad f) => Functor (WhenMissing f x) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal fmap :: (a -> b) -> WhenMissing f x a -> WhenMissing f x b # (<$) :: a -> WhenMissing f x b -> WhenMissing f x a # | |
Functor m => Functor (ErrorT e m) | |
Functor m => Functor (ExceptT e m) | |
Functor m => Functor (IdentityT m) | |
Functor m => Functor (ReaderT r m) | |
Functor m => Functor (StateT s m) | |
Functor m => Functor (StateT s m) | |
Functor m => Functor (WriterT w m) | |
Functor m => Functor (WriterT w m) | |
Functor ((,,) a b) | Since: base-4.14.0.0 |
(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 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 LiftedRep -> Type) | Since: base-4.9.0.0 |
Functor f => Functor (WhenMatched f x y) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal 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 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 (ContT r m) | |
Functor ((,,,) a b c) | Since: base-4.14.0.0 |
Functor ((->) r) | Since: base-2.1 |
(Functor f, Functor g) => Functor (Compose f g) | Since: base-4.9.0.0 |
(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 f => Functor (WhenMatched f k x y) | Since: containers-0.5.9 |
Defined in Data.Map.Internal 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 m => Functor (RWST r w s m) | |
Functor m => Functor (RWST r w s m) | |
class Monad m => MonadFail (m :: Type -> Type) where #
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: base-4.9.0.0
Instances
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:
(<*>
) =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 #
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)
(*>) :: 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 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 #
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: base-2.1 |
Applicative Complex | Since: base-4.9.0.0 |
Applicative Identity | Since: base-4.8.0.0 |
Applicative First | Since: base-4.8.0.0 |
Applicative Last | Since: base-4.8.0.0 |
Applicative Down | Since: base-4.11.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 Dual | Since: base-4.8.0.0 |
Applicative Product | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Applicative STM | Since: base-4.8.0.0 |
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 ReadPrec | Since: base-4.6.0.0 |
Applicative Seq | Since: containers-0.5.4 |
Applicative Tree | |
Applicative IO | Since: base-2.1 |
Applicative Q | |
Applicative Query | |
Applicative X | |
Applicative FocusQuery Source # | |
Defined in XMonad.Hooks.Focus pure :: a -> FocusQuery a # (<*>) :: FocusQuery (a -> b) -> FocusQuery a -> FocusQuery b # liftA2 :: (a -> b -> c) -> FocusQuery a -> FocusQuery b -> FocusQuery c # (*>) :: FocusQuery a -> FocusQuery b -> FocusQuery b # (<*) :: FocusQuery a -> FocusQuery b -> FocusQuery a # | |
Applicative Parser Source # | |
Applicative PureX Source # | |
Applicative NonEmpty | Since: base-4.9.0.0 |
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 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 # | |
Arrow a => Applicative (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow 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 (StateL s) | Since: base-4.0 |
Applicative (StateR s) | Since: base-4.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Applicative m => Applicative (ListT m) | |
(Functor m, Monad m) => Applicative (MaybeT m) | |
Applicative (TwoD a) Source # | |
Applicative m => Applicative (Invisible m) Source # | |
Defined in XMonad.Util.Invisible | |
Applicative (StateQuery s) Source # | |
Defined in XMonad.Util.WindowState pure :: a -> StateQuery s a # (<*>) :: StateQuery s (a -> b) -> StateQuery s a -> StateQuery s b # liftA2 :: (a -> b -> c) -> StateQuery s a -> StateQuery s b -> StateQuery s c # (*>) :: StateQuery s a -> StateQuery s b -> StateQuery s b # (<*) :: StateQuery s a -> StateQuery s b -> StateQuery s a # | |
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 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 m => Applicative (Kleisli m a) | Since: base-4.14.0.0 |
Defined in Control.Arrow | |
Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
Applicative f => Applicative (Ap f) | Since: base-4.12.0.0 |
Applicative f => Applicative (Alt f) | Since: base-4.8.0.0 |
Applicative f => Applicative (Rec1 f) | Since: base-4.9.0.0 |
(Applicative f, Monad f) => Applicative (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal 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 # | |
(Functor m, Monad m) => Applicative (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
(Functor m, Monad m) => Applicative (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
Applicative m => Applicative (IdentityT m) | |
Defined in Control.Monad.Trans.Identity | |
Applicative m => Applicative (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
(Functor m, Monad m) => Applicative (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy | |
(Monoid w, Applicative m) => Applicative (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Strict | |
(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 | |
(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 |
(Monad f, Applicative f) => Applicative (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal 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 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 (ContT r m) | |
(Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) | Since: base-4.14.0.0 |
Defined in GHC.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 | |
(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 |
(Monad f, Applicative f) => Applicative (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal 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 # | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Lazy | |
(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Strict |
class Foldable (t :: TYPE LiftedRep -> Type) where #
The Foldable class represents data structures that can be reduced to a summary value one element at a time. Strict left-associative folds are a good fit for space-efficient reduction, while lazy right-associative folds are a good fit for corecursive iteration, or for folds that short-circuit after processing an initial subsequence of the structure's elements.
Instances can be derived automatically by enabling the DeriveFoldable
extension. For example, a derived instance for a binary tree might be:
{-# LANGUAGE DeriveFoldable #-} data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) deriving Foldable
A more detailed description can be found in the Overview section of Data.Foldable.
For the class laws see the Laws section of Data.Foldable.
fold :: Monoid m => t m -> m #
Given a structure with elements whose type is a Monoid
, combine them
via the monoid's (
operator. This fold is right-associative and
lazy in the accumulator. When you need a strict left-associative fold,
use <>
)foldMap'
instead, with id
as the map.
Examples
Basic usage:
>>>
fold [[1, 2, 3], [4, 5], [6], []]
[1,2,3,4,5,6]
>>>
fold $ Node (Leaf (Sum 1)) (Sum 3) (Leaf (Sum 5))
Sum {getSum = 9}
Folds of unbounded structures do not terminate when the monoid's
(
operator is strict:<>
)
>>>
fold (repeat Nothing)
* Hangs forever *
Lazy corecursive folds of unbounded structures are fine:
>>>
take 12 $ fold $ map (\i -> [i..i+2]) [0..]
[0,1,2,1,2,3,2,3,4,3,4,5]>>>
sum $ take 4000000 $ fold $ map (\i -> [i..i+2]) [0..]
2666668666666
foldMap :: Monoid m => (a -> m) -> t a -> m #
Map each element of the structure into a monoid, and combine the
results with (
. This fold is right-associative and lazy in the
accumulator. For strict left-associative folds consider <>
)foldMap'
instead.
Examples
Basic usage:
>>>
foldMap Sum [1, 3, 5]
Sum {getSum = 9}
>>>
foldMap Product [1, 3, 5]
Product {getProduct = 15}
>>>
foldMap (replicate 3) [1, 2, 3]
[1,1,1,2,2,2,3,3,3]
When a Monoid's (
is lazy in its second argument, <>
)foldMap
can
return a result even from an unbounded structure. For example, lazy
accumulation enables Data.ByteString.Builder to efficiently serialise
large data structures and produce the output incrementally:
>>>
import qualified Data.ByteString.Lazy as L
>>>
import qualified Data.ByteString.Builder as B
>>>
let bld :: Int -> B.Builder; bld i = B.intDec i <> B.word8 0x20
>>>
let lbs = B.toLazyByteString $ foldMap bld [0..]
>>>
L.take 64 lbs
"0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24"
foldMap' :: Monoid m => (a -> m) -> t a -> m #
A left-associative variant of foldMap
that is strict in the
accumulator. Use this method for strict reduction when partial
results are merged via (
.<>
)
Examples
Define a Monoid
over finite bit strings under xor
. Use it to
strictly compute the xor
of a list of Int
values.
>>>
:set -XGeneralizedNewtypeDeriving
>>>
import Data.Bits (Bits, FiniteBits, xor, zeroBits)
>>>
import Data.Foldable (foldMap')
>>>
import Numeric (showHex)
>>>
>>>
newtype X a = X a deriving (Eq, Bounded, Enum, Bits, FiniteBits)
>>>
instance Bits a => Semigroup (X a) where X a <> X b = X (a `xor` b)
>>>
instance Bits a => Monoid (X a) where mempty = X zeroBits
>>>
>>>
let bits :: [Int]; bits = [0xcafe, 0xfeed, 0xdeaf, 0xbeef, 0x5411]
>>>
(\ (X a) -> showString "0x" . showHex a $ "") $ foldMap' X bits
"0x42"
Since: base-4.13.0.0
foldr :: (a -> b -> b) -> b -> t a -> b #
Right-associative fold of a structure, lazy in the accumulator.
In the case of lists, foldr
, when applied to a binary operator, a
starting value (typically the right-identity of the operator), and a
list, reduces the list using the binary operator, from right to left:
foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
Note that since the head of the resulting expression is produced by an
application of the operator to the first element of the list, given an
operator lazy in its right argument, foldr
can produce a terminating
expression from an unbounded list.
For a general Foldable
structure this should be semantically identical
to,
foldr f z =foldr
f z .toList
Examples
Basic usage:
>>>
foldr (||) False [False, True, False]
True
>>>
foldr (||) False []
False
>>>
foldr (\c acc -> acc ++ [c]) "foo" ['a', 'b', 'c', 'd']
"foodcba"
Infinite structures
⚠️ Applying foldr
to infinite structures usually doesn't terminate.
It may still terminate under one of the following conditions:
- the folding function is short-circuiting
- the folding function is lazy on its second argument
Short-circuiting
(
short-circuits on ||
)True
values, so the following terminates
because there is a True
value finitely far from the left side:
>>>
foldr (||) False (True : repeat False)
True
But the following doesn't terminate:
>>>
foldr (||) False (repeat False ++ [True])
* Hangs forever *
Laziness in the second argument
Applying foldr
to infinite structures terminates when the operator is
lazy in its second argument (the initial accumulator is never used in
this case, and so could be left undefined
, but []
is more clear):
>>>
take 5 $ foldr (\i acc -> i : fmap (+3) acc) [] (repeat 1)
[1,4,7,10,13]
foldr' :: (a -> b -> b) -> b -> t a -> b #
Right-associative fold of a structure, strict in the accumulator. This is rarely what you want.
Since: base-4.6.0.0
foldl :: (b -> a -> b) -> b -> t a -> b #
Left-associative fold of a structure, lazy in the accumulator. This is rarely what you want, but can work well for structures with efficient right-to-left sequencing and an operator that is lazy in its left argument.
In the case of lists, foldl
, when applied to a binary operator, a
starting value (typically the left-identity of the operator), and a
list, reduces the list using the binary operator, from left to right:
foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
Note that to produce the outermost application of the operator the
entire input list must be traversed. Like all left-associative folds,
foldl
will diverge if given an infinite list.
If you want an efficient strict left-fold, you probably want to use
foldl'
instead of foldl
. The reason for this is that the latter
does not force the inner results (e.g. z `f` x1
in the above
example) before applying them to the operator (e.g. to (`f` x2)
).
This results in a thunk chain \(\mathcal{O}(n)\) elements long, which
then must be evaluated from the outside-in.
For a general Foldable
structure this should be semantically identical
to:
foldl f z =foldl
f z .toList
Examples
The first example is a strict fold, which in practice is best performed
with foldl'
.
>>>
foldl (+) 42 [1,2,3,4]
52
Though the result below is lazy, the input is reversed before prepending it to the initial accumulator, so corecursion begins only after traversing the entire input string.
>>>
foldl (\acc c -> c : acc) "abcd" "efgh"
"hgfeabcd"
A left fold of a structure that is infinite on the right cannot terminate, even when for any finite input the fold just returns the initial accumulator:
>>>
foldl (\a _ -> a) 0 $ repeat 1
* Hangs forever *
WARNING: When it comes to lists, you always want to use either foldl'
or foldr
instead.
foldl' :: (b -> a -> b) -> b -> t a -> b #
Left-associative fold of a structure but with strict application of the operator.
This ensures that each step of the fold is forced to Weak Head Normal
Form before being applied, avoiding the collection of thunks that would
otherwise occur. This is often what you want to strictly reduce a
finite structure to a single strict result (e.g. sum
).
For a general Foldable
structure this should be semantically identical
to,
foldl' f z =foldl'
f z .toList
Since: base-4.6.0.0
foldr1 :: (a -> a -> a) -> t a -> a #
A variant of foldr
that has no base case,
and thus may only be applied to non-empty structures.
This function is non-total and will raise a runtime exception if the structure happens to be empty.
Examples
Basic usage:
>>>
foldr1 (+) [1..4]
10
>>>
foldr1 (+) []
Exception: Prelude.foldr1: empty list
>>>
foldr1 (+) Nothing
*** Exception: foldr1: empty structure
>>>
foldr1 (-) [1..4]
-2
>>>
foldr1 (&&) [True, False, True, True]
False
>>>
foldr1 (||) [False, False, True, True]
True
>>>
foldr1 (+) [1..]
* Hangs forever *
foldl1 :: (a -> a -> a) -> t a -> a #
A variant of foldl
that has no base case,
and thus may only be applied to non-empty structures.
This function is non-total and will raise a runtime exception if the structure happens to be empty.
foldl1
f =foldl1
f .toList
Examples
Basic usage:
>>>
foldl1 (+) [1..4]
10
>>>
foldl1 (+) []
*** Exception: Prelude.foldl1: empty list
>>>
foldl1 (+) Nothing
*** Exception: foldl1: empty structure
>>>
foldl1 (-) [1..4]
-8
>>>
foldl1 (&&) [True, False, True, True]
False
>>>
foldl1 (||) [False, False, True, True]
True
>>>
foldl1 (+) [1..]
* Hangs forever *
Test whether the structure is empty. The default implementation is Left-associative and lazy in both the initial element and the accumulator. Thus optimised for structures where the first element can be accessed in constant time. Structures where this is not the case should have a non-default implementation.
Examples
Basic usage:
>>>
null []
True
>>>
null [1]
False
null
is expected to terminate even for infinite structures.
The default implementation terminates provided the structure
is bounded on the left (there is a leftmost element).
>>>
null [1..]
False
Since: base-4.8.0.0
Returns the size/length of a finite structure as an Int
. The
default implementation just counts elements starting with the leftmost.
Instances for structures that can compute the element count faster
than via element-by-element counting, should provide a specialised
implementation.
Examples
Basic usage:
>>>
length []
0
>>>
length ['a', 'b', 'c']
3>>>
length [1..]
* Hangs forever *
Since: base-4.8.0.0
elem :: Eq a => a -> t a -> Bool infix 4 #
Does the element occur in the structure?
Note: elem
is often used in infix form.
Examples
Basic usage:
>>>
3 `elem` []
False
>>>
3 `elem` [1,2]
False
>>>
3 `elem` [1,2,3,4,5]
True
For infinite structures, the default implementation of elem
terminates if the sought-after value exists at a finite distance
from the left side of the structure:
>>>
3 `elem` [1..]
True
>>>
3 `elem` ([4..] ++ [3])
* Hangs forever *
Since: base-4.8.0.0
maximum :: Ord a => t a -> a #
The largest element of a non-empty structure.
This function is non-total and will raise a runtime exception if the structure happens to be empty. A structure that supports random access and maintains its elements in order should provide a specialised implementation to return the maximum in faster than linear time.
Examples
Basic usage:
>>>
maximum [1..10]
10
>>>
maximum []
*** Exception: Prelude.maximum: empty list
>>>
maximum Nothing
*** Exception: maximum: empty structure
WARNING: This function is partial for possibly-empty structures like lists.
Since: base-4.8.0.0
minimum :: Ord a => t a -> a #
The least element of a non-empty structure.
This function is non-total and will raise a runtime exception if the structure happens to be empty. A structure that supports random access and maintains its elements in order should provide a specialised implementation to return the minimum in faster than linear time.
Examples
Basic usage:
>>>
minimum [1..10]
1
>>>
minimum []
*** Exception: Prelude.minimum: empty list
>>>
minimum Nothing
*** Exception: minimum: empty structure
WARNING: This function is partial for possibly-empty structures like lists.
Since: base-4.8.0.0
The sum
function computes the sum of the numbers of a structure.
Examples
Basic usage:
>>>
sum []
0
>>>
sum [42]
42
>>>
sum [1..10]
55
>>>
sum [4.1, 2.0, 1.7]
7.8
>>>
sum [1..]
* Hangs forever *
Since: base-4.8.0.0
product :: Num a => t a -> a #
The product
function computes the product of the numbers of a
structure.
Examples
Basic usage:
>>>
product []
1
>>>
product [42]
42
>>>
product [1..10]
3628800
>>>
product [4.1, 2.0, 1.7]
13.939999999999998
>>>
product [1..]
* Hangs forever *
Since: base-4.8.0.0
Instances
Foldable ZipList | Since: base-4.9.0.0 |
Defined in Control.Applicative 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 # | |
Foldable Complex | Since: base-4.9.0.0 |
Defined in Data.Complex fold :: Monoid m => Complex m -> m # foldMap :: Monoid m => (a -> m) -> Complex a -> m # foldMap' :: Monoid m => (a -> m) -> Complex a -> m # foldr :: (a -> b -> b) -> b -> Complex a -> b # foldr' :: (a -> b -> b) -> b -> Complex a -> b # foldl :: (b -> a -> b) -> b -> Complex a -> b # foldl' :: (b -> a -> b) -> b -> Complex a -> b # foldr1 :: (a -> a -> a) -> Complex a -> a # foldl1 :: (a -> a -> a) -> Complex a -> a # elem :: Eq a => a -> Complex a -> Bool # maximum :: Ord a => Complex a -> a # minimum :: Ord a => Complex a -> a # | |
Foldable Identity | Since: base-4.8.0.0 |
Defined in Data.Functor.Identity fold :: Monoid m => Identity m -> m # foldMap :: Monoid m => (a -> m) -> Identity a -> m # foldMap' :: Monoid m => (a -> m) -> Identity a -> m # foldr :: (a -> b -> b) -> b -> Identity a -> b # foldr' :: (a -> b -> b) -> b -> Identity a -> b # foldl :: (b -> a -> b) -> b -> Identity a -> b # foldl' :: (b -> a -> b) -> b -> Identity a -> b # foldr1 :: (a -> a -> a) -> Identity a -> a # foldl1 :: (a -> a -> a) -> Identity a -> a # elem :: Eq a => a -> Identity a -> Bool # maximum :: Ord a => Identity a -> a # minimum :: Ord a => Identity a -> a # | |
Foldable First | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => First m -> m # foldMap :: Monoid m => (a -> m) -> First a -> m # foldMap' :: Monoid m => (a -> m) -> First a -> m # foldr :: (a -> b -> b) -> b -> First a -> b # foldr' :: (a -> b -> b) -> b -> First a -> b # foldl :: (b -> a -> b) -> b -> First a -> b # foldl' :: (b -> a -> b) -> b -> First a -> b # foldr1 :: (a -> a -> a) -> First a -> a # foldl1 :: (a -> a -> a) -> First a -> a # elem :: Eq a => a -> First a -> Bool # maximum :: Ord a => First a -> a # minimum :: Ord a => First a -> a # | |
Foldable Last | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Last m -> m # foldMap :: Monoid m => (a -> m) -> Last a -> m # foldMap' :: Monoid m => (a -> m) -> Last a -> m # foldr :: (a -> b -> b) -> b -> Last a -> b # foldr' :: (a -> b -> b) -> b -> Last a -> b # foldl :: (b -> a -> b) -> b -> Last a -> b # foldl' :: (b -> a -> b) -> b -> Last a -> b # foldr1 :: (a -> a -> a) -> Last a -> a # foldl1 :: (a -> a -> a) -> Last a -> a # elem :: Eq a => a -> Last a -> Bool # maximum :: Ord a => Last a -> a # | |
Foldable Down | Since: base-4.12.0.0 |
Defined in Data.Foldable 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 # | |
Foldable First | Since: base-4.9.0.0 |
Defined in Data.Semigroup fold :: Monoid m => First m -> m # foldMap :: Monoid m => (a -> m) -> First a -> m # foldMap' :: Monoid m => (a -> m) -> First a -> m # foldr :: (a -> b -> b) -> b -> First a -> b # foldr' :: (a -> b -> b) -> b -> First a -> b # foldl :: (b -> a -> b) -> b -> First a -> b # foldl' :: (b -> a -> b) -> b -> First a -> b # foldr1 :: (a -> a -> a) -> First a -> a # foldl1 :: (a -> a -> a) -> First a -> a # elem :: Eq a => a -> First a -> Bool # maximum :: Ord a => First a -> a # minimum :: Ord a => First a -> a # | |
Foldable Last | Since: base-4.9.0.0 |
Defined in Data.Semigroup fold :: Monoid m => Last m -> m # foldMap :: Monoid m => (a -> m) -> Last a -> m # foldMap' :: Monoid m => (a -> m) -> Last a -> m # foldr :: (a -> b -> b) -> b -> Last a -> b # foldr' :: (a -> b -> b) -> b -> Last a -> b # foldl :: (b -> a -> b) -> b -> Last a -> b # foldl' :: (b -> a -> b) -> b -> Last a -> b # foldr1 :: (a -> a -> a) -> Last a -> a # foldl1 :: (a -> a -> a) -> Last a -> a # elem :: Eq a => a -> Last a -> Bool # maximum :: Ord a => Last a -> a # | |
Foldable Max | Since: base-4.9.0.0 |
Defined in Data.Semigroup fold :: Monoid m => Max m -> m # foldMap :: Monoid m => (a -> m) -> Max a -> m # foldMap' :: Monoid m => (a -> m) -> Max a -> m # foldr :: (a -> b -> b) -> b -> Max a -> b # foldr' :: (a -> b -> b) -> b -> Max a -> b # foldl :: (b -> a -> b) -> b -> Max a -> b # foldl' :: (b -> a -> b) -> b -> Max a -> b # foldr1 :: (a -> a -> a) -> Max a -> a # foldl1 :: (a -> a -> a) -> Max a -> a # elem :: Eq a => a -> Max a -> Bool # maximum :: Ord a => Max a -> a # | |
Foldable Min | Since: base-4.9.0.0 |
Defined in Data.Semigroup fold :: Monoid m => Min m -> m # foldMap :: Monoid m => (a -> m) -> Min a -> m # foldMap' :: Monoid m => (a -> m) -> Min a -> m # foldr :: (a -> b -> b) -> b -> Min a -> b # foldr' :: (a -> b -> b) -> b -> Min a -> b # foldl :: (b -> a -> b) -> b -> Min a -> b # foldl' :: (b -> a -> b) -> b -> Min a -> b # foldr1 :: (a -> a -> a) -> Min a -> a # foldl1 :: (a -> a -> a) -> Min a -> a # elem :: Eq a => a -> Min a -> Bool # maximum :: Ord a => Min a -> a # | |
Foldable Dual | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Dual m -> m # foldMap :: Monoid m => (a -> m) -> Dual a -> m # foldMap' :: Monoid m => (a -> m) -> Dual a -> m # foldr :: (a -> b -> b) -> b -> Dual a -> b # foldr' :: (a -> b -> b) -> b -> Dual a -> b # foldl :: (b -> a -> b) -> b -> Dual a -> b # foldl' :: (b -> a -> b) -> b -> Dual a -> b # foldr1 :: (a -> a -> a) -> Dual a -> a # foldl1 :: (a -> a -> a) -> Dual a -> a # elem :: Eq a => a -> Dual a -> Bool # maximum :: Ord a => Dual a -> a # | |
Foldable Product | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Product m -> m # foldMap :: Monoid m => (a -> m) -> Product a -> m # foldMap' :: Monoid m => (a -> m) -> Product a -> m # foldr :: (a -> b -> b) -> b -> Product a -> b # foldr' :: (a -> b -> b) -> b -> Product a -> b # foldl :: (b -> a -> b) -> b -> Product a -> b # foldl' :: (b -> a -> b) -> b -> Product a -> b # foldr1 :: (a -> a -> a) -> Product a -> a # foldl1 :: (a -> a -> a) -> Product a -> a # elem :: Eq a => a -> Product a -> Bool # maximum :: Ord a => Product a -> a # minimum :: Ord a => Product a -> a # | |
Foldable Sum | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Sum m -> m # foldMap :: Monoid m => (a -> m) -> Sum a -> m # foldMap' :: Monoid m => (a -> m) -> Sum a -> m # foldr :: (a -> b -> b) -> b -> Sum a -> b # foldr' :: (a -> b -> b) -> b -> Sum a -> b # foldl :: (b -> a -> b) -> b -> Sum a -> b # foldl' :: (b -> a -> b) -> b -> Sum a -> b # foldr1 :: (a -> a -> a) -> Sum a -> a # foldl1 :: (a -> a -> a) -> Sum a -> a # elem :: Eq a => a -> Sum a -> Bool # maximum :: Ord a => Sum a -> a # | |
Foldable Par1 | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => Par1 m -> m # foldMap :: Monoid m => (a -> m) -> Par1 a -> m # foldMap' :: Monoid m => (a -> m) -> Par1 a -> m # foldr :: (a -> b -> b) -> b -> Par1 a -> b # foldr' :: (a -> b -> b) -> b -> Par1 a -> b # foldl :: (b -> a -> b) -> b -> Par1 a -> b # foldl' :: (b -> a -> b) -> b -> Par1 a -> b # foldr1 :: (a -> a -> a) -> Par1 a -> a # foldl1 :: (a -> a -> a) -> Par1 a -> a # elem :: Eq a => a -> Par1 a -> Bool # maximum :: Ord a => Par1 a -> a # | |
Foldable IntMap | Folds in order of increasing key. |
Defined in Data.IntMap.Internal fold :: Monoid m => IntMap m -> m # foldMap :: Monoid m => (a -> m) -> IntMap a -> m # foldMap' :: Monoid m => (a -> m) -> IntMap a -> m # foldr :: (a -> b -> b) -> b -> IntMap a -> b # foldr' :: (a -> b -> b) -> b -> IntMap a -> b # foldl :: (b -> a -> b) -> b -> IntMap a -> b # foldl' :: (b -> a -> b) -> b -> IntMap a -> b # foldr1 :: (a -> a -> a) -> IntMap a -> a # foldl1 :: (a -> a -> a) -> IntMap a -> a # elem :: Eq a => a -> IntMap a -> Bool # maximum :: Ord a => IntMap a -> a # minimum :: Ord a => IntMap a -> a # | |
Foldable Digit | |
Defined in Data.Sequence.Internal fold :: Monoid m => Digit m -> m # foldMap :: Monoid m => (a -> m) -> Digit a -> m # foldMap' :: Monoid m => (a -> m) -> Digit a -> m # foldr :: (a -> b -> b) -> b -> Digit a -> b # foldr' :: (a -> b -> b) -> b -> Digit a -> b # foldl :: (b -> a -> b) -> b -> Digit a -> b # foldl' :: (b -> a -> b) -> b -> Digit a -> b # foldr1 :: (a -> a -> a) -> Digit a -> a # foldl1 :: (a -> a -> a) -> Digit a -> a # elem :: Eq a => a -> Digit a -> Bool # maximum :: Ord a => Digit a -> a # minimum :: Ord a => Digit a -> a # | |
Foldable Elem | |
Defined in Data.Sequence.Internal fold :: Monoid m => Elem m -> m # foldMap :: Monoid m => (a -> m) -> Elem a -> m # foldMap' :: Monoid m => (a -> m) -> Elem a -> m # foldr :: (a -> b -> b) -> b -> Elem a -> b # foldr' :: (a -> b -> b) -> b -> Elem a -> b # foldl :: (b -> a -> b) -> b -> Elem a -> b # foldl' :: (b -> a -> b) -> b -> Elem a -> b # foldr1 :: (a -> a -> a) -> Elem a -> a # foldl1 :: (a -> a -> a) -> Elem a -> a # elem :: Eq a => a -> Elem a -> Bool # maximum :: Ord a => Elem a -> a # | |
Foldable FingerTree | |
Defined in Data.Sequence.Internal fold :: Monoid m => FingerTree m -> m # foldMap :: Monoid m => (a -> m) -> FingerTree a -> m # foldMap' :: Monoid m => (a -> m) -> FingerTree a -> m # foldr :: (a -> b -> b) -> b -> FingerTree a -> b # foldr' :: (a -> b -> b) -> b -> FingerTree a -> b # foldl :: (b -> a -> b) -> b -> FingerTree a -> b # foldl' :: (b -> a -> b) -> b -> FingerTree a -> b # foldr1 :: (a -> a -> a) -> FingerTree a -> a # foldl1 :: (a -> a -> a) -> FingerTree a -> a # toList :: FingerTree a -> [a] # null :: FingerTree a -> Bool # length :: FingerTree a -> Int # elem :: Eq a => a -> FingerTree a -> Bool # maximum :: Ord a => FingerTree a -> a # minimum :: Ord a => FingerTree a -> a # sum :: Num a => FingerTree a -> a # product :: Num a => FingerTree a -> a # | |
Foldable Node | |
Defined in Data.Sequence.Internal fold :: Monoid m => Node m -> m # foldMap :: Monoid m => (a -> m) -> Node a -> m # foldMap' :: Monoid m => (a -> m) -> Node a -> m # foldr :: (a -> b -> b) -> b -> Node a -> b # foldr' :: (a -> b -> b) -> b -> Node a -> b # foldl :: (b -> a -> b) -> b -> Node a -> b # foldl' :: (b -> a -> b) -> b -> Node a -> b # foldr1 :: (a -> a -> a) -> Node a -> a # foldl1 :: (a -> a -> a) -> Node a -> a # elem :: Eq a => a -> Node a -> Bool # maximum :: Ord a => Node a -> a # | |
Foldable Seq | |
Defined in Data.Sequence.Internal fold :: Monoid m => Seq m -> m # foldMap :: Monoid m => (a -> m) -> Seq a -> m # foldMap' :: Monoid m => (a -> m) -> Seq a -> m # foldr :: (a -> b -> b) -> b -> Seq a -> b # foldr' :: (a -> b -> b) -> b -> Seq a -> b # foldl :: (b -> a -> b) -> b -> Seq a -> b # foldl' :: (b -> a -> b) -> b -> Seq a -> b # foldr1 :: (a -> a -> a) -> Seq a -> a # foldl1 :: (a -> a -> a) -> Seq a -> a # elem :: Eq a => a -> Seq a -> Bool # maximum :: Ord a => Seq a -> a # | |
Foldable ViewL | |
Defined in Data.Sequence.Internal fold :: Monoid m => ViewL m -> m # foldMap :: Monoid m => (a -> m) -> ViewL a -> m # foldMap' :: Monoid m => (a -> m) -> ViewL a -> m # foldr :: (a -> b -> b) -> b -> ViewL a -> b # foldr' :: (a -> b -> b) -> b -> ViewL a -> b # foldl :: (b -> a -> b) -> b -> ViewL a -> b # foldl' :: (b -> a -> b) -> b -> ViewL a -> b # foldr1 :: (a -> a -> a) -> ViewL a -> a # foldl1 :: (a -> a -> a) -> ViewL a -> a # elem :: Eq a => a -> ViewL a -> Bool # maximum :: Ord a => ViewL a -> a # minimum :: Ord a => ViewL a -> a # | |
Foldable ViewR | |
Defined in Data.Sequence.Internal fold :: Monoid m => ViewR m -> m # foldMap :: Monoid m => (a -> m) -> ViewR a -> m # foldMap' :: Monoid m => (a -> m) -> ViewR a -> m # foldr :: (a -> b -> b) -> b -> ViewR a -> b # foldr' :: (a -> b -> b) -> b -> ViewR a -> b # foldl :: (b -> a -> b) -> b -> ViewR a -> b # foldl' :: (b -> a -> b) -> b -> ViewR a -> b # foldr1 :: (a -> a -> a) -> ViewR a -> a # foldl1 :: (a -> a -> a) -> ViewR a -> a # elem :: Eq a => a -> ViewR a -> Bool # maximum :: Ord a => ViewR a -> a # minimum :: Ord a => ViewR a -> a # | |
Foldable Set | Folds in order of increasing key. |
Defined in Data.Set.Internal fold :: Monoid m => Set m -> m # foldMap :: Monoid m => (a -> m) -> Set a -> m # foldMap' :: Monoid m => (a -> m) -> Set a -> m # foldr :: (a -> b -> b) -> b -> Set a -> b # foldr' :: (a -> b -> b) -> b -> Set a -> b # foldl :: (b -> a -> b) -> b -> Set a -> b # foldl' :: (b -> a -> b) -> b -> Set a -> b # foldr1 :: (a -> a -> a) -> Set a -> a # foldl1 :: (a -> a -> a) -> Set a -> a # elem :: Eq a => a -> Set a -> Bool # maximum :: Ord a => Set a -> a # | |
Foldable Tree | |
Defined in Data.Tree fold :: Monoid m => Tree m -> m # foldMap :: Monoid m => (a -> m) -> Tree a -> m # foldMap' :: Monoid m => (a -> m) -> Tree a -> m # foldr :: (a -> b -> b) -> b -> Tree a -> b # foldr' :: (a -> b -> b) -> b -> Tree a -> b # foldl :: (b -> a -> b) -> b -> Tree a -> b # foldl' :: (b -> a -> b) -> b -> Tree a -> b # foldr1 :: (a -> a -> a) -> Tree a -> a # foldl1 :: (a -> a -> a) -> Tree a -> a # elem :: Eq a => a -> Tree a -> Bool # maximum :: Ord a => Tree a -> a # | |
Foldable Directories' | |
Defined in XMonad.Core fold :: Monoid m => Directories' m -> m # foldMap :: Monoid m => (a -> m) -> Directories' a -> m # foldMap' :: Monoid m => (a -> m) -> Directories' a -> m # foldr :: (a -> b -> b) -> b -> Directories' a -> b # foldr' :: (a -> b -> b) -> b -> Directories' a -> b # foldl :: (b -> a -> b) -> b -> Directories' a -> b # foldl' :: (b -> a -> b) -> b -> Directories' a -> b # foldr1 :: (a -> a -> a) -> Directories' a -> a # foldl1 :: (a -> a -> a) -> Directories' a -> a # toList :: Directories' a -> [a] # null :: Directories' a -> Bool # length :: Directories' a -> Int # elem :: Eq a => a -> Directories' a -> Bool # maximum :: Ord a => Directories' a -> a # minimum :: Ord a => Directories' a -> a # sum :: Num a => Directories' a -> a # product :: Num a => Directories' a -> a # | |
Foldable Stack | |
Defined in XMonad.StackSet fold :: Monoid m => Stack m -> m # foldMap :: Monoid m => (a -> m) -> Stack a -> m # foldMap' :: Monoid m => (a -> m) -> Stack a -> m # foldr :: (a -> b -> b) -> b -> Stack a -> b # foldr' :: (a -> b -> b) -> b -> Stack a -> b # foldl :: (b -> a -> b) -> b -> Stack a -> b # foldl' :: (b -> a -> b) -> b -> Stack a -> b # foldr1 :: (a -> a -> a) -> Stack a -> a # foldl1 :: (a -> a -> a) -> Stack a -> a # elem :: Eq a => a -> Stack a -> Bool # maximum :: Ord a => Stack a -> a # minimum :: Ord a => Stack a -> a # | |
Foldable Cursors Source # | |
Defined in XMonad.Actions.WorkspaceCursors fold :: Monoid m => Cursors m -> m # foldMap :: Monoid m => (a -> m) -> Cursors a -> m # foldMap' :: Monoid m => (a -> m) -> Cursors a -> m # foldr :: (a -> b -> b) -> b -> Cursors a -> b # foldr' :: (a -> b -> b) -> b -> Cursors a -> b # foldl :: (b -> a -> b) -> b -> Cursors a -> b # foldl' :: (b -> a -> b) -> b -> Cursors a -> b # foldr1 :: (a -> a -> a) -> Cursors a -> a # foldl1 :: (a -> a -> a) -> Cursors a -> a # elem :: Eq a => a -> Cursors a -> Bool # maximum :: Ord a => Cursors a -> a # minimum :: Ord a => Cursors a -> a # | |
Foldable NonEmpty | Since: base-4.9.0.0 |
Defined in Data.Foldable 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 # | |
Foldable Maybe | Since: base-2.1 |
Defined in Data.Foldable 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 # | |
Foldable Solo | Since: base-4.15 |
Defined in Data.Foldable fold :: Monoid m => Solo m -> m # foldMap :: Monoid m => (a -> m) -> Solo a -> m # foldMap' :: Monoid m => (a -> m) -> Solo a -> m # foldr :: (a -> b -> b) -> b -> Solo a -> b # foldr' :: (a -> b -> b) -> b -> Solo a -> b # foldl :: (b -> a -> b) -> b -> Solo a -> b # foldl' :: (b -> a -> b) -> b -> Solo a -> b # foldr1 :: (a -> a -> a) -> Solo a -> a # foldl1 :: (a -> a -> a) -> Solo a -> a # elem :: Eq a => a -> Solo a -> Bool # maximum :: Ord a => Solo a -> a # | |
Foldable [] | Since: base-2.1 |
Defined in Data.Foldable fold :: Monoid m => [m] -> m # foldMap :: Monoid m => (a -> m) -> [a] -> m # foldMap' :: Monoid m => (a -> m) -> [a] -> m # foldr :: (a -> b -> b) -> b -> [a] -> b # foldr' :: (a -> b -> b) -> b -> [a] -> b # foldl :: (b -> a -> b) -> b -> [a] -> b # foldl' :: (b -> a -> b) -> b -> [a] -> b # foldr1 :: (a -> a -> a) -> [a] -> a # foldl1 :: (a -> a -> a) -> [a] -> a # elem :: Eq a => a -> [a] -> Bool # maximum :: Ord a => [a] -> a # | |
Foldable (Either a) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Either a m -> m # foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # toList :: Either a a0 -> [a0] # length :: Either a a0 -> Int # elem :: Eq a0 => a0 -> Either a a0 -> Bool # maximum :: Ord a0 => Either a a0 -> a0 # minimum :: Ord a0 => Either a a0 -> a0 # | |
Foldable (Proxy :: TYPE LiftedRep -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable 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 # | |
Foldable (Arg a) | Since: base-4.9.0.0 |
Defined in Data.Semigroup fold :: Monoid m => Arg a m -> m # foldMap :: Monoid m => (a0 -> m) -> Arg a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> Arg a a0 -> m # foldr :: (a0 -> b -> b) -> b -> Arg a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> Arg a a0 -> b # foldl :: (b -> a0 -> b) -> b -> Arg a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> Arg a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> Arg a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> Arg a a0 -> a0 # elem :: Eq a0 => a0 -> Arg a a0 -> Bool # maximum :: Ord a0 => Arg a a0 -> a0 # minimum :: Ord a0 => Arg a a0 -> a0 # | |
Foldable (Array i) | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Array i m -> m # foldMap :: Monoid m => (a -> m) -> Array i a -> m # foldMap' :: Monoid m => (a -> m) -> Array i a -> m # foldr :: (a -> b -> b) -> b -> Array i a -> b # foldr' :: (a -> b -> b) -> b -> Array i a -> b # foldl :: (b -> a -> b) -> b -> Array i a -> b # foldl' :: (b -> a -> b) -> b -> Array i a -> b # foldr1 :: (a -> a -> a) -> Array i a -> a # foldl1 :: (a -> a -> a) -> Array i a -> a # elem :: Eq a => a -> Array i a -> Bool # maximum :: Ord a => Array i a -> a # minimum :: Ord a => Array i a -> a # | |
Foldable (U1 :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => U1 m -> m # foldMap :: Monoid m => (a -> m) -> U1 a -> m # foldMap' :: Monoid m => (a -> m) -> U1 a -> m # foldr :: (a -> b -> b) -> b -> U1 a -> b # foldr' :: (a -> b -> b) -> b -> U1 a -> b # foldl :: (b -> a -> b) -> b -> U1 a -> b # foldl' :: (b -> a -> b) -> b -> U1 a -> b # foldr1 :: (a -> a -> a) -> U1 a -> a # foldl1 :: (a -> a -> a) -> U1 a -> a # elem :: Eq a => a -> U1 a -> Bool # maximum :: Ord a => U1 a -> a # | |
Foldable (UAddr :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => UAddr m -> m # foldMap :: Monoid m => (a -> m) -> UAddr a -> m # foldMap' :: Monoid m => (a -> m) -> UAddr a -> m # foldr :: (a -> b -> b) -> b -> UAddr a -> b # foldr' :: (a -> b -> b) -> b -> UAddr a -> b # foldl :: (b -> a -> b) -> b -> UAddr a -> b # foldl' :: (b -> a -> b) -> b -> UAddr a -> b # foldr1 :: (a -> a -> a) -> UAddr a -> a # foldl1 :: (a -> a -> a) -> UAddr a -> a # elem :: Eq a => a -> UAddr a -> Bool # maximum :: Ord a => UAddr a -> a # minimum :: Ord a => UAddr a -> a # | |
Foldable (UChar :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => UChar m -> m # foldMap :: Monoid m => (a -> m) -> UChar a -> m # foldMap' :: Monoid m => (a -> m) -> UChar a -> m # foldr :: (a -> b -> b) -> b -> UChar a -> b # foldr' :: (a -> b -> b) -> b -> UChar a -> b # foldl :: (b -> a -> b) -> b -> UChar a -> b # foldl' :: (b -> a -> b) -> b -> UChar a -> b # foldr1 :: (a -> a -> a) -> UChar a -> a # foldl1 :: (a -> a -> a) -> UChar a -> a # elem :: Eq a => a -> UChar a -> Bool # maximum :: Ord a => UChar a -> a # minimum :: Ord a => UChar a -> a # | |
Foldable (UDouble :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable 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 # | |
Foldable (UFloat :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable 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 # | |
Foldable (UInt :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => UInt m -> m # foldMap :: Monoid m => (a -> m) -> UInt a -> m # foldMap' :: Monoid m => (a -> m) -> UInt a -> m # foldr :: (a -> b -> b) -> b -> UInt a -> b # foldr' :: (a -> b -> b) -> b -> UInt a -> b # foldl :: (b -> a -> b) -> b -> UInt a -> b # foldl' :: (b -> a -> b) -> b -> UInt a -> b # foldr1 :: (a -> a -> a) -> UInt a -> a # foldl1 :: (a -> a -> a) -> UInt a -> a # elem :: Eq a => a -> UInt a -> Bool # maximum :: Ord a => UInt a -> a # | |
Foldable (UWord :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable 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 # | |
Foldable (V1 :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => V1 m -> m # foldMap :: Monoid m => (a -> m) -> V1 a -> m # foldMap' :: Monoid m => (a -> m) -> V1 a -> m # foldr :: (a -> b -> b) -> b -> V1 a -> b # foldr' :: (a -> b -> b) -> b -> V1 a -> b # foldl :: (b -> a -> b) -> b -> V1 a -> b # foldl' :: (b -> a -> b) -> b -> V1 a -> b # foldr1 :: (a -> a -> a) -> V1 a -> a # foldl1 :: (a -> a -> a) -> V1 a -> a # elem :: Eq a => a -> V1 a -> Bool # maximum :: Ord a => V1 a -> a # | |
Foldable (Map k) | Folds in order of increasing key. |
Defined in Data.Map.Internal fold :: Monoid m => Map k m -> m # foldMap :: Monoid m => (a -> m) -> Map k a -> m # foldMap' :: Monoid m => (a -> m) -> Map k a -> m # foldr :: (a -> b -> b) -> b -> Map k a -> b # foldr' :: (a -> b -> b) -> b -> Map k a -> b # foldl :: (b -> a -> b) -> b -> Map k a -> b # foldl' :: (b -> a -> b) -> b -> Map k a -> b # foldr1 :: (a -> a -> a) -> Map k a -> a # foldl1 :: (a -> a -> a) -> Map k a -> a # elem :: Eq a => a -> Map k a -> Bool # maximum :: Ord a => Map k a -> a # minimum :: Ord a => Map k a -> a # | |
Foldable f => Foldable (ListT f) | |
Defined in Control.Monad.Trans.List fold :: Monoid m => ListT f m -> m # foldMap :: Monoid m => (a -> m) -> ListT f a -> m # foldMap' :: Monoid m => (a -> m) -> ListT f a -> m # foldr :: (a -> b -> b) -> b -> ListT f a -> b # foldr' :: (a -> b -> b) -> b -> ListT f a -> b # foldl :: (b -> a -> b) -> b -> ListT f a -> b # foldl' :: (b -> a -> b) -> b -> ListT f a -> b # foldr1 :: (a -> a -> a) -> ListT f a -> a # foldl1 :: (a -> a -> a) -> ListT f a -> a # elem :: Eq a => a -> ListT f a -> Bool # maximum :: Ord a => ListT f a -> a # minimum :: Ord a => ListT f a -> a # | |
Foldable f => Foldable (MaybeT f) | |
Defined in Control.Monad.Trans.Maybe fold :: Monoid m => MaybeT f m -> m # foldMap :: Monoid m => (a -> m) -> MaybeT f a -> m # foldMap' :: Monoid m => (a -> m) -> MaybeT f a -> m # foldr :: (a -> b -> b) -> b -> MaybeT f a -> b # foldr' :: (a -> b -> b) -> b -> MaybeT f a -> b # foldl :: (b -> a -> b) -> b -> MaybeT f a -> b # foldl' :: (b -> a -> b) -> b -> MaybeT f a -> b # foldr1 :: (a -> a -> a) -> MaybeT f a -> a # foldl1 :: (a -> a -> a) -> MaybeT f a -> a # elem :: Eq a => a -> MaybeT f a -> Bool # maximum :: Ord a => MaybeT f a -> a # minimum :: Ord a => MaybeT f a -> a # | |
Foldable (History k) Source # | |
Defined in XMonad.Util.History fold :: Monoid m => History k m -> m # foldMap :: Monoid m => (a -> m) -> History k a -> m # foldMap' :: Monoid m => (a -> m) -> History k a -> m # foldr :: (a -> b -> b) -> b -> History k a -> b # foldr' :: (a -> b -> b) -> b -> History k a -> b # foldl :: (b -> a -> b) -> b -> History k a -> b # foldl' :: (b -> a -> b) -> b -> History k a -> b # foldr1 :: (a -> a -> a) -> History k a -> a # foldl1 :: (a -> a -> a) -> History k a -> a # toList :: History k a -> [a] # length :: History k a -> Int # elem :: Eq a => a -> History k a -> Bool # maximum :: Ord a => History k a -> a # minimum :: Ord a => History k a -> a # | |
Foldable ((,) a) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => (a, m) -> m # foldMap :: Monoid m => (a0 -> m) -> (a, a0) -> m # foldMap' :: Monoid m => (a0 -> m) -> (a, a0) -> m # foldr :: (a0 -> b -> b) -> b -> (a, a0) -> b # foldr' :: (a0 -> b -> b) -> b -> (a, a0) -> b # foldl :: (b -> a0 -> b) -> b -> (a, a0) -> b # foldl' :: (b -> a0 -> b) -> b -> (a, a0) -> b # foldr1 :: (a0 -> a0 -> a0) -> (a, a0) -> a0 # foldl1 :: (a0 -> a0 -> a0) -> (a, a0) -> a0 # elem :: Eq a0 => a0 -> (a, a0) -> Bool # maximum :: Ord a0 => (a, a0) -> a0 # minimum :: Ord a0 => (a, a0) -> a0 # | |
Foldable (Const m :: TYPE LiftedRep -> Type) | Since: base-4.7.0.0 |
Defined in Data.Functor.Const 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 # | |
Foldable f => Foldable (Ap f) | Since: base-4.12.0.0 |
Defined in Data.Foldable fold :: Monoid m => Ap f m -> m # foldMap :: Monoid m => (a -> m) -> Ap f a -> m # foldMap' :: Monoid m => (a -> m) -> Ap f a -> m # foldr :: (a -> b -> b) -> b -> Ap f a -> b # foldr' :: (a -> b -> b) -> b -> Ap f a -> b # foldl :: (b -> a -> b) -> b -> Ap f a -> b # foldl' :: (b -> a -> b) -> b -> Ap f a -> b # foldr1 :: (a -> a -> a) -> Ap f a -> a # foldl1 :: (a -> a -> a) -> Ap f a -> a # elem :: Eq a => a -> Ap f a -> Bool # maximum :: Ord a => Ap f a -> a # | |
Foldable f => Foldable (Alt f) | Since: base-4.12.0.0 |
Defined in Data.Foldable fold :: Monoid m => Alt f m -> m # foldMap :: Monoid m => (a -> m) -> Alt f a -> m # foldMap' :: Monoid m => (a -> m) -> Alt f a -> m # foldr :: (a -> b -> b) -> b -> Alt f a -> b # foldr' :: (a -> b -> b) -> b -> Alt f a -> b # foldl :: (b -> a -> b) -> b -> Alt f a -> b # foldl' :: (b -> a -> b) -> b -> Alt f a -> b # foldr1 :: (a -> a -> a) -> Alt f a -> a # foldl1 :: (a -> a -> a) -> Alt f a -> a # elem :: Eq a => a -> Alt f a -> Bool # maximum :: Ord a => Alt f a -> a # minimum :: Ord a => Alt f a -> a # | |
Foldable f => Foldable (Rec1 f) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => Rec1 f m -> m # foldMap :: Monoid m => (a -> m) -> Rec1 f a -> m # foldMap' :: Monoid m => (a -> m) -> Rec1 f a -> m # foldr :: (a -> b -> b) -> b -> Rec1 f a -> b # foldr' :: (a -> b -> b) -> b -> Rec1 f a -> b # foldl :: (b -> a -> b) -> b -> Rec1 f a -> b # foldl' :: (b -> a -> b) -> b -> Rec1 f a -> b # foldr1 :: (a -> a -> a) -> Rec1 f a -> a # foldl1 :: (a -> a -> a) -> Rec1 f a -> a # elem :: Eq a => a -> Rec1 f a -> Bool # maximum :: Ord a => Rec1 f a -> a # minimum :: Ord a => Rec1 f a -> a # | |
Foldable f => Foldable (ErrorT e f) | |
Defined in Control.Monad.Trans.Error fold :: Monoid m => ErrorT e f m -> m # foldMap :: Monoid m => (a -> m) -> ErrorT e f a -> m # foldMap' :: Monoid m => (a -> m) -> ErrorT e f a -> m # foldr :: (a -> b -> b) -> b -> ErrorT e f a -> b # foldr' :: (a -> b -> b) -> b -> ErrorT e f a -> b # foldl :: (b -> a -> b) -> b -> ErrorT e f a -> b # foldl' :: (b -> a -> b) -> b -> ErrorT e f a -> b # foldr1 :: (a -> a -> a) -> ErrorT e f a -> a # foldl1 :: (a -> a -> a) -> ErrorT e f a -> a # toList :: ErrorT e f a -> [a] # null :: ErrorT e f a -> Bool # length :: ErrorT e f a -> Int # elem :: Eq a => a -> ErrorT e f a -> Bool # maximum :: Ord a => ErrorT e f a -> a # minimum :: Ord a => ErrorT e f a -> a # | |
Foldable f => Foldable (ExceptT e f) | |
Defined in Control.Monad.Trans.Except fold :: Monoid m => ExceptT e f m -> m # foldMap :: Monoid m => (a -> m) -> ExceptT e f a -> m # foldMap' :: Monoid m => (a -> m) -> ExceptT e f a -> m # foldr :: (a -> b -> b) -> b -> ExceptT e f a -> b # foldr' :: (a -> b -> b) -> b -> ExceptT e f a -> b # foldl :: (b -> a -> b) -> b -> ExceptT e f a -> b # foldl' :: (b -> a -> b) -> b -> ExceptT e f a -> b # foldr1 :: (a -> a -> a) -> ExceptT e f a -> a # foldl1 :: (a -> a -> a) -> ExceptT e f a -> a # toList :: ExceptT e f a -> [a] # null :: ExceptT e f a -> Bool # length :: ExceptT e f a -> Int # elem :: Eq a => a -> ExceptT e f a -> Bool # maximum :: Ord a => ExceptT e f a -> a # minimum :: Ord a => ExceptT e f a -> a # | |
Foldable f => Foldable (IdentityT f) | |
Defined in Control.Monad.Trans.Identity fold :: Monoid m => IdentityT f m -> m # foldMap :: Monoid m => (a -> m) -> IdentityT f a -> m # foldMap' :: Monoid m => (a -> m) -> IdentityT f a -> m # foldr :: (a -> b -> b) -> b -> IdentityT f a -> b # foldr' :: (a -> b -> b) -> b -> IdentityT f a -> b # foldl :: (b -> a -> b) -> b -> IdentityT f a -> b # foldl' :: (b -> a -> b) -> b -> IdentityT f a -> b # foldr1 :: (a -> a -> a) -> IdentityT f a -> a # foldl1 :: (a -> a -> a) -> IdentityT f a -> a # toList :: IdentityT f a -> [a] # null :: IdentityT f a -> Bool # length :: IdentityT f a -> Int # elem :: Eq a => a -> IdentityT f a -> Bool # maximum :: Ord a => IdentityT f a -> a # minimum :: Ord a => IdentityT f a -> a # | |
Foldable f => Foldable (WriterT w f) | |
Defined in Control.Monad.Trans.Writer.Lazy fold :: Monoid m => WriterT w f m -> m # foldMap :: Monoid m => (a -> m) -> WriterT w f a -> m # foldMap' :: Monoid m => (a -> m) -> WriterT w f a -> m # foldr :: (a -> b -> b) -> b -> WriterT w f a -> b # foldr' :: (a -> b -> b) -> b -> WriterT w f a -> b # foldl :: (b -> a -> b) -> b -> WriterT w f a -> b # foldl' :: (b -> a -> b) -> b -> WriterT w f a -> b # foldr1 :: (a -> a -> a) -> WriterT w f a -> a # foldl1 :: (a -> a -> a) -> WriterT w f a -> a # toList :: WriterT w f a -> [a] # null :: WriterT w f a -> Bool # length :: WriterT w f a -> Int # elem :: Eq a => a -> WriterT w f a -> Bool # maximum :: Ord a => WriterT w f a -> a # minimum :: Ord a => WriterT w f a -> a # | |
Foldable f => Foldable (WriterT w f) | |
Defined in Control.Monad.Trans.Writer.Strict fold :: Monoid m => WriterT w f m -> m # foldMap :: Monoid m => (a -> m) -> WriterT w f a -> m # foldMap' :: Monoid m => (a -> m) -> WriterT w f a -> m # foldr :: (a -> b -> b) -> b -> WriterT w f a -> b # foldr' :: (a -> b -> b) -> b -> WriterT w f a -> b # foldl :: (b -> a -> b) -> b -> WriterT w f a -> b # foldl' :: (b -> a -> b) -> b -> WriterT w f a -> b # foldr1 :: (a -> a -> a) -> WriterT w f a -> a # foldl1 :: (a -> a -> a) -> WriterT w f a -> a # toList :: WriterT w f a -> [a] # null :: WriterT w f a -> Bool # length :: WriterT w f a -> Int # elem :: Eq a => a -> WriterT w f a -> Bool # maximum :: Ord a => WriterT w f a -> a # minimum :: Ord a => WriterT w f a -> a # | |
(Foldable f, Foldable g) => Foldable (Product f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Product fold :: Monoid m => Product f g m -> m # foldMap :: Monoid m => (a -> m) -> Product f g a -> m # foldMap' :: Monoid m => (a -> m) -> Product f g a -> m # foldr :: (a -> b -> b) -> b -> Product f g a -> b # foldr' :: (a -> b -> b) -> b -> Product f g a -> b # foldl :: (b -> a -> b) -> b -> Product f g a -> b # foldl' :: (b -> a -> b) -> b -> Product f g a -> b # foldr1 :: (a -> a -> a) -> Product f g a -> a # foldl1 :: (a -> a -> a) -> Product f g a -> a # toList :: Product f g a -> [a] # null :: Product f g a -> Bool # length :: Product f g a -> Int # elem :: Eq a => a -> Product f g a -> Bool # maximum :: Ord a => Product f g a -> a # minimum :: Ord a => Product f g a -> a # | |
(Foldable f, Foldable g) => Foldable (Sum f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Sum fold :: Monoid m => Sum f g m -> m # foldMap :: Monoid m => (a -> m) -> Sum f g a -> m # foldMap' :: Monoid m => (a -> m) -> Sum f g a -> m # foldr :: (a -> b -> b) -> b -> Sum f g a -> b # foldr' :: (a -> b -> b) -> b -> Sum f g a -> b # foldl :: (b -> a -> b) -> b -> Sum f g a -> b # foldl' :: (b -> a -> b) -> b -> Sum f g a -> b # foldr1 :: (a -> a -> a) -> Sum f g a -> a # foldl1 :: (a -> a -> a) -> Sum f g a -> a # elem :: Eq a => a -> Sum f g a -> Bool # maximum :: Ord a => Sum f g a -> a # minimum :: Ord a => Sum f g a -> a # | |
(Foldable f, Foldable g) => Foldable (f :*: g) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => (f :*: g) m -> m # foldMap :: Monoid m => (a -> m) -> (f :*: g) a -> m # foldMap' :: Monoid m => (a -> m) -> (f :*: g) a -> m # foldr :: (a -> b -> b) -> b -> (f :*: g) a -> b # foldr' :: (a -> b -> b) -> b -> (f :*: g) a -> b # foldl :: (b -> a -> b) -> b -> (f :*: g) a -> b # foldl' :: (b -> a -> b) -> b -> (f :*: g) a -> b # foldr1 :: (a -> a -> a) -> (f :*: g) a -> a # foldl1 :: (a -> a -> a) -> (f :*: g) a -> a # toList :: (f :*: g) a -> [a] # length :: (f :*: g) a -> Int # elem :: Eq a => a -> (f :*: g) a -> Bool # maximum :: Ord a => (f :*: g) a -> a # minimum :: Ord a => (f :*: g) a -> a # | |
(Foldable f, Foldable g) => Foldable (f :+: g) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => (f :+: g) m -> m # foldMap :: Monoid m => (a -> m) -> (f :+: g) a -> m # foldMap' :: Monoid m => (a -> m) -> (f :+: g) a -> m # foldr :: (a -> b -> b) -> b -> (f :+: g) a -> b # foldr' :: (a -> b -> b) -> b -> (f :+: g) a -> b # foldl :: (b -> a -> b) -> b -> (f :+: g) a -> b # foldl' :: (b -> a -> b) -> b -> (f :+: g) a -> b # foldr1 :: (a -> a -> a) -> (f :+: g) a -> a # foldl1 :: (a -> a -> a) -> (f :+: g) a -> a # toList :: (f :+: g) a -> [a] # length :: (f :+: g) a -> Int # elem :: Eq a => a -> (f :+: g) a -> Bool # maximum :: Ord a => (f :+: g) a -> a # minimum :: Ord a => (f :+: g) a -> a # | |
Foldable (K1 i c :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => K1 i c m -> m # foldMap :: Monoid m => (a -> m) -> K1 i c a -> m # foldMap' :: Monoid m => (a -> m) -> K1 i c a -> m # foldr :: (a -> b -> b) -> b -> K1 i c a -> b # foldr' :: (a -> b -> b) -> b -> K1 i c a -> b # foldl :: (b -> a -> b) -> b -> K1 i c a -> b # foldl' :: (b -> a -> b) -> b -> K1 i c a -> b # foldr1 :: (a -> a -> a) -> K1 i c a -> a # foldl1 :: (a -> a -> a) -> K1 i c a -> a # elem :: Eq a => a -> K1 i c a -> Bool # maximum :: Ord a => K1 i c a -> a # minimum :: Ord a => K1 i c a -> a # | |
(Foldable f, Foldable g) => Foldable (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose fold :: Monoid m => Compose f g m -> m # foldMap :: Monoid m => (a -> m) -> Compose f g a -> m # foldMap' :: Monoid m => (a -> m) -> Compose f g a -> m # foldr :: (a -> b -> b) -> b -> Compose f g a -> b # foldr' :: (a -> b -> b) -> b -> Compose f g a -> b # foldl :: (b -> a -> b) -> b -> Compose f g a -> b # foldl' :: (b -> a -> b) -> b -> Compose f g a -> b # foldr1 :: (a -> a -> a) -> Compose f g a -> a # foldl1 :: (a -> a -> a) -> Compose f g a -> a # toList :: Compose f g a -> [a] # null :: Compose f g a -> Bool # length :: Compose f g a -> Int # elem :: Eq a => a -> Compose f g a -> Bool # maximum :: Ord a => Compose f g a -> a # minimum :: Ord a => Compose f g a -> a # | |
(Foldable f, Foldable g) => Foldable (f :.: g) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => (f :.: g) m -> m # foldMap :: Monoid m => (a -> m) -> (f :.: g) a -> m # foldMap' :: Monoid m => (a -> m) -> (f :.: g) a -> m # foldr :: (a -> b -> b) -> b -> (f :.: g) a -> b # foldr' :: (a -> b -> b) -> b -> (f :.: g) a -> b # foldl :: (b -> a -> b) -> b -> (f :.: g) a -> b # foldl' :: (b -> a -> b) -> b -> (f :.: g) a -> b # foldr1 :: (a -> a -> a) -> (f :.: g) a -> a # foldl1 :: (a -> a -> a) -> (f :.: g) a -> a # toList :: (f :.: g) a -> [a] # length :: (f :.: g) a -> Int # elem :: Eq a => a -> (f :.: g) a -> Bool # maximum :: Ord a => (f :.: g) a -> a # minimum :: Ord a => (f :.: g) a -> a # | |
Foldable f => Foldable (M1 i c f) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => M1 i c f m -> m # foldMap :: Monoid m => (a -> m) -> M1 i c f a -> m # foldMap' :: Monoid m => (a -> m) -> M1 i c f a -> m # foldr :: (a -> b -> b) -> b -> M1 i c f a -> b # foldr' :: (a -> b -> b) -> b -> M1 i c f a -> b # foldl :: (b -> a -> b) -> b -> M1 i c f a -> b # foldl' :: (b -> a -> b) -> b -> M1 i c f a -> b # foldr1 :: (a -> a -> a) -> M1 i c f a -> a # foldl1 :: (a -> a -> a) -> M1 i c f a -> a # elem :: Eq a => a -> M1 i c f a -> Bool # maximum :: Ord a => M1 i c f a -> a # minimum :: Ord a => M1 i c f a -> a # |
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.
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
(<>) :: Semigroup a => a -> a -> a infixr 6 #
An associative operation.
>>>
[1,2,3] <> [4,5,6]
[1,2,3,4,5,6]
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)<>
zSemigroup
law)- Concatenation
mconcat
=foldr
(<>
)mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
NOTE: Semigroup
is a superclass of Monoid
since base-4.11.0.0.
Identity of mappend
>>>
"Hello world" <> mempty
"Hello world"
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 All | Since: base-2.1 |
Monoid Any | Since: base-2.1 |
Monoid ByteString | |
Defined in Data.ByteString.Internal.Type mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid ByteString | |
Defined in Data.ByteString.Lazy.Internal mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid ShortByteString | |
Defined in Data.ByteString.Short.Internal mappend :: ShortByteString -> ShortByteString -> ShortByteString # mconcat :: [ShortByteString] -> ShortByteString # | |
Monoid IntSet | |
Monoid Ordering | Since: base-2.1 |
Monoid Opacity Source # | |
Monoid RescreenConfig Source # | |
Defined in XMonad.Hooks.Rescreen mappend :: RescreenConfig -> RescreenConfig -> RescreenConfig # mconcat :: [RescreenConfig] -> RescreenConfig # | |
Monoid StatusBarConfig Source # | |
Defined in XMonad.Hooks.StatusBar mappend :: StatusBarConfig -> StatusBarConfig -> StatusBarConfig # mconcat :: [StatusBarConfig] -> StatusBarConfig # | |
Monoid WallpaperList Source # | |
Defined in XMonad.Hooks.WallpaperSetter mempty :: WallpaperList # mappend :: WallpaperList -> WallpaperList -> WallpaperList # mconcat :: [WallpaperList] -> WallpaperList # | |
Monoid () | Since: base-2.1 |
FiniteBits a => Monoid (And a) | This constraint is arguably too strong. However,
as some types (such as Since: base-4.16 |
FiniteBits a => Monoid (Iff a) | This constraint is arguably
too strong. However, as some types (such as Since: base-4.16 |
Bits a => Monoid (Ior a) | Since: base-4.16 |
Bits a => Monoid (Xor a) | Since: base-4.16 |
Monoid a => Monoid (Identity a) | Since: base-4.9.0.0 |
Ord a => Monoid (Max a) | Since: base-4.8.0.0 |
Ord a => Monoid (Min a) | Since: base-4.8.0.0 |
Monoid (First a) | Since: base-2.1 |
Monoid (Last a) | Since: base-2.1 |
Monoid a => Monoid (Down a) | Since: base-4.11.0.0 |
(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 mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Monoid (Endo a) | Since: base-2.1 |
Num a => Monoid (Product a) | Since: base-2.1 |
Num a => Monoid (Sum a) | Since: base-2.1 |
Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
Monoid (IntMap a) | |
Monoid (Seq a) | |
Monoid (MergeSet a) | |
Ord a => Monoid (Set a) | |
Monoid a => Monoid (IO a) | Since: base-4.9.0.0 |
Monoid a => Monoid (Q a) | Since: template-haskell-2.17.0.0 |
Monoid a => Monoid (Query a) | |
Monoid a => Monoid (X a) | |
Monoid a => Monoid (FocusQuery a) Source # | |
Defined in XMonad.Hooks.Focus mempty :: FocusQuery a # mappend :: FocusQuery a -> FocusQuery a -> FocusQuery a # mconcat :: [FocusQuery a] -> FocusQuery a # | |
Monoid (Parser a) Source # | |
Monoid a => Monoid (PureX a) Source # | |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Monoid a => Monoid (a) | Since: base-4.15 |
Monoid [a] | Since: base-2.1 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Monoid (U1 p) | Since: base-4.12.0.0 |
Ord k => Monoid (Map k v) | |
Monoid b => Monoid (a -> b) | Since: base-2.1 |
(Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1 |
Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0 |
Alternative f => Monoid (Alt f a) | Since: base-4.8.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
Storable Bool | Since: base-2.1 |
Defined in Foreign.Storable | |
Bits Bool | Interpret Since: base-4.7.0.0 |
Defined in GHC.Bits (.&.) :: Bool -> Bool -> Bool # (.|.) :: Bool -> Bool -> Bool # complement :: Bool -> Bool # shift :: Bool -> Int -> Bool # rotate :: Bool -> Int -> Bool # setBit :: Bool -> Int -> Bool # clearBit :: Bool -> Int -> Bool # complementBit :: Bool -> Int -> Bool # testBit :: Bool -> Int -> Bool # bitSizeMaybe :: Bool -> Maybe Int # shiftL :: Bool -> Int -> Bool # unsafeShiftL :: Bool -> Int -> Bool # shiftR :: Bool -> Int -> Bool # unsafeShiftR :: Bool -> Int -> Bool # rotateL :: Bool -> Int -> Bool # | |
FiniteBits Bool | Since: base-4.7.0.0 |
Defined in GHC.Bits | |
Bounded Bool | Since: base-2.1 |
Enum Bool | Since: base-2.1 |
Generic Bool | |
SingKind Bool | Since: base-4.9.0.0 |
Defined in GHC.Generics type DemoteRep Bool | |
Ix Bool | Since: base-2.1 |
Read Bool | Since: base-2.1 |
Show Bool | Since: base-2.1 |
NFData Bool | |
Defined in Control.DeepSeq | |
Eq Bool | |
Ord Bool | |
Random Bool | |
Finite Bool | |
Defined in System.Random.GFinite | |
Uniform Bool | |
Defined in System.Random.Internal uniformM :: StatefulGen g m => g -> m Bool # | |
UniformRange Bool | |
Defined in System.Random.Internal | |
SingI 'False | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
SingI 'True | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
Lift Bool | |
type DemoteRep Bool | |
Defined in GHC.Generics | |
type Rep Bool | Since: base-4.6.0.0 |
data Sing (a :: Bool) | |
The character type Char
is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) code points (i.e. characters, see
http://www.unicode.org/ for details). This set extends the ISO 8859-1
(Latin-1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char
.
To convert a Char
to or from the corresponding Int
value defined
by Unicode, use toEnum
and fromEnum
from the
Enum
class respectively (or equivalently ord
and
chr
).
Instances
Storable Char | Since: base-2.1 |
Defined in Foreign.Storable | |
Bounded Char | Since: base-2.1 |
Enum Char | Since: base-2.1 |
Ix Char | Since: base-2.1 |
Read Char | Since: base-2.1 |
Show Char | Since: base-2.1 |
IsChar Char | Since: base-2.1 |
PrintfArg Char | Since: base-2.1 |
Defined in Text.Printf formatArg :: Char -> FieldFormatter # parseFormat :: Char -> ModifierParser # | |
NFData Char | |
Defined in Control.DeepSeq | |
Eq Char | |
Ord Char | |
Random Char | |
Finite Char | |
Defined in System.Random.GFinite | |
Uniform Char | |
Defined in System.Random.Internal uniformM :: StatefulGen g m => g -> m Char # | |
UniformRange Char | |
Defined in System.Random.Internal | |
ErrorList Char | |
Defined in Control.Monad.Trans.Error | |
HasColorizer String Source # | |
Defined in XMonad.Actions.GridSelect | |
PPrint Char Source # | |
Lift Char | |
Generic1 (URec Char :: k -> Type) | |
Foldable (UChar :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Defined in Data.Foldable fold :: Monoid m => UChar m -> m # foldMap :: Monoid m => (a -> m) -> UChar a -> m # foldMap' :: Monoid m => (a -> m) -> UChar a -> m # foldr :: (a -> b -> b) -> b -> UChar a -> b # foldr' :: (a -> b -> b) -> b -> UChar a -> b # foldl :: (b -> a -> b) -> b -> UChar a -> b # foldl' :: (b -> a -> b) -> b -> UChar a -> b # foldr1 :: (a -> a -> a) -> UChar a -> a # foldl1 :: (a -> a -> a) -> UChar a -> a # elem :: Eq a => a -> UChar a -> Bool # maximum :: Ord a => UChar a -> a # minimum :: Ord a => UChar a -> a # | |
Traversable (UChar :: Type -> Type) | Since: base-4.9.0.0 |
HasName [Char] Source # | |
Functor (URec Char :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
HasName (X (), String) Source # | |
HasName (X (), [String]) Source # | |
HasName (NamedAction, String) Source # | |
Defined in XMonad.Util.NamedActions showName :: (NamedAction, String) -> [String] getAction :: (NamedAction, String) -> X () | |
Generic (URec Char p) | |
Show (URec Char p) | Since: base-4.9.0.0 |
Eq (URec Char p) | Since: base-4.9.0.0 |
Ord (URec Char p) | Since: base-4.9.0.0 |
data URec Char (p :: k) | Used for marking occurrences of Since: base-4.9.0.0 |
type Compare (a :: Char) (b :: Char) | |
Defined in Data.Type.Ord | |
type Rep1 (URec Char :: k -> Type) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
type Rep (URec Char p) | Since: base-4.9.0.0 |
Defined in GHC.Generics |
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
MonadFail Maybe | Since: base-4.9.0.0 |
Defined in Control.Monad.Fail | |
MonadFix Maybe | Since: base-2.1 |
Defined in Control.Monad.Fix | |
Foldable Maybe | Since: base-2.1 |
Defined in Data.Foldable 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 # | |
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 |
Traversable Maybe | Since: base-2.1 |
Alternative Maybe | Since: base-2.1 |
Applicative Maybe | Since: base-2.1 |
Functor Maybe | Since: base-2.1 |
Monad Maybe | Since: base-2.1 |
MonadPlus Maybe | Since: base-2.1 |
NFData1 Maybe | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Generic1 Maybe | |
MonadError () Maybe | Since: mtl-2.2.2 |
Defined in Control.Monad.Error.Class throwError :: () -> Maybe a # catchError :: Maybe a -> (() -> Maybe a) -> Maybe a # | |
Lift a => Lift (Maybe a :: Type) | |
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) | |
SingKind a => SingKind (Maybe a) | Since: base-4.9.0.0 |
Defined in GHC.Generics type DemoteRep (Maybe a) | |
Read a => Read (Maybe a) | Since: base-2.1 |
Show a => Show (Maybe a) | Since: base-2.1 |
Default (Maybe a) | |
Defined in Data.Default.Class | |
NFData a => NFData (Maybe a) | |
Defined in Control.DeepSeq | |
Eq a => Eq (Maybe a) | Since: base-2.1 |
Ord a => Ord (Maybe a) | Since: base-2.1 |
Finite a => Finite (Maybe a) | |
Defined in System.Random.GFinite cardinality :: Proxy# (Maybe a) -> Cardinality toFinite :: Integer -> Maybe a fromFinite :: Maybe a -> Integer | |
PPrint a => PPrint (Maybe a) Source # | |
SingI ('Nothing :: Maybe a) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
(Show s, Read s, Typeable s) => MonadState (Maybe s) (StateQuery s) Source # | Instance of MonadState for StateQuery. |
Defined in XMonad.Util.WindowState get :: StateQuery s (Maybe s) # put :: Maybe s -> StateQuery s () # state :: (Maybe s -> (a, Maybe s)) -> StateQuery s a # | |
SingI a2 => SingI ('Just a2 :: Maybe a1) | Since: base-4.9.0.0 |
Defined in GHC.Generics | |
type Rep1 Maybe | Since: base-4.6.0.0 |
type DemoteRep (Maybe a) | |
Defined in GHC.Generics | |
type Rep (Maybe a) | Since: base-4.6.0.0 |
Defined in GHC.Generics | |
data Sing (b :: Maybe a) | |
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
replicateM_ :: Applicative m => Int -> m a -> m () #
replicateM :: Applicative m => Int -> m a -> m [a] #
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)
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #
The mapAndUnzipM
function maps its first argument over a list, returning
the result as a pair of lists. This function is mainly used with complicated
data structures or a state monad.
forever :: Applicative f => f a -> f b #
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 non-terminating.
If the action is in a
and short-circuits after some number of iterations.
then MonadPlus
actually returns forever
mzero
, effectively short-circuiting its caller.
foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () #
Like foldM
, but discards the result.
foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
The foldM
function is analogous to foldl
, except that its result is
encapsulated in a monad. Note that foldM
works from left-to-right over
the list arguments. This could be an issue where (
and the `folded
function' are not commutative.>>
)
foldM f a1 [x1, x2, ..., xm] == do a2 <- f a1 x1 a3 <- f a2 x2 ... f am xm
If right-to-left evaluation is required, the input list should be reversed.
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter
function.
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right composition of Kleisli arrows.
'(bs
' can be understood as the >=>
cs) ado
expression
do b <- bs a cs b
isSubsequenceOf :: Eq a => [a] -> [a] -> Bool #
The isSubsequenceOf
function takes two lists and returns True
if all
the elements of the first list occur, in order, in the second. The
elements do not have to occur consecutively.
is equivalent to isSubsequenceOf
x y
.elem
x (subsequences
y)
Examples
>>>
isSubsequenceOf "GHC" "The Glorious Haskell Compiler"
True>>>
isSubsequenceOf ['a','d'..'z'] ['a'..'z']
True>>>
isSubsequenceOf [1..10] [10,9..0]
False
Since: base-4.8.0.0
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"])
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"])
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #
for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) #
foldMapDefault :: (Traversable t, Monoid m) => (a -> m) -> t a -> m #
fmapDefault :: Traversable t => (a -> b) -> t a -> t b #
This function may be used as a value for fmap
in a Functor
instance, provided that traverse
is defined. (Using
fmapDefault
with a Traversable
instance defined only by
sequenceA
will result in infinite recursion.)
fmapDefault
f ≡runIdentity
.traverse
(Identity
. f)
Lists, but with an Applicative
functor based on zipping.
ZipList | |
|
Instances
Foldable ZipList | Since: base-4.9.0.0 |
Defined in Control.Applicative 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 |
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 |
NFData1 ZipList | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Generic1 ZipList | |
IsList (ZipList a) | Since: base-4.15.0.0 |
Generic (ZipList a) | |
Read a => Read (ZipList a) | Since: base-4.7.0.0 |
Show a => Show (ZipList a) | Since: base-4.7.0.0 |
NFData a => NFData (ZipList a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (ZipList a) | Since: base-4.7.0.0 |
Ord a => Ord (ZipList a) | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
type Rep1 ZipList | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
type Item (ZipList a) | |
type Rep (ZipList a) | Since: base-4.7.0.0 |
Defined in Control.Applicative |
newtype WrappedMonad (m :: Type -> Type) a #
WrapMonad | |
|
Instances
newtype WrappedArrow (a :: Type -> Type -> Type) b c #
WrapArrow | |
|
Instances
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 *> final
Left "it failed">>>
runExcept $ optional canFail *> final
Right 42
The Const
functor.
Instances
Generic1 (Const a :: k -> Type) | |
Bifunctor (Const :: Type -> Type -> Type) | Since: base-4.8.0.0 |
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 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 LiftedRep -> Type) | Since: base-4.9.0.0 |
NFData2 (Const :: Type -> Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Foldable (Const m :: TYPE LiftedRep -> Type) | Since: base-4.7.0.0 |
Defined in Data.Functor.Const 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 # | |
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 | |
Show a => Show1 (Const a :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
Functor (Const m :: Type -> Type) | Since: base-2.1 |
NFData a => NFData1 (Const a :: TYPE LiftedRep -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
IsString a => IsString (Const a b) | Since: base-4.9.0.0 |
Defined in Data.String fromString :: String -> Const a b # | |
Storable a => Storable (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
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 Data.Functor.Const (.&.) :: 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 Data.Functor.Const finiteBitSize :: Const a b -> Int # countLeadingZeros :: Const a b -> Int # countTrailingZeros :: Const a b -> Int # | |
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 Data.Functor.Const 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 Data.Functor.Const 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 Data.Functor.Const 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 # | |
Generic (Const a b) | |
Ix a => Ix (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const 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 |
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 Data.Functor.Const | |
Real a => Real (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const 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 |
NFData a => NFData (Const a b) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (Const a b) | Since: base-4.9.0.0 |
Ord a => Ord (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
type Rep1 (Const a :: k -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
type Rep (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const |
traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f () #
Map each element of a structure to an Applicative
action, evaluate these
actions from left to right, and ignore the results. For a version that
doesn't ignore the results see traverse
.
traverse_
is just like mapM_
, but generalised to Applicative
actions.
Examples
Basic usage:
>>>
traverse_ print ["Hello", "world", "!"]
"Hello" "world" "!"
sequence_ :: (Foldable t, Monad m) => t (m a) -> m () #
Evaluate each monadic action in the structure from left to right,
and ignore the results. For a version that doesn't ignore the
results see sequence
.
sequence_
is just like sequenceA_
, but specialised to monadic
actions.
sequenceA_ :: (Foldable t, Applicative f) => t (f a) -> f () #
Evaluate each action in the structure from left to right, and
ignore the results. For a version that doesn't ignore the results
see sequenceA
.
sequenceA_
is just like sequence_
, but generalised to Applicative
actions.
Examples
Basic usage:
>>>
sequenceA_ [print "Hello", print "world", print "!"]
"Hello" "world" "!"
or :: Foldable t => t Bool -> Bool #
or
returns the disjunction of a container of Bools. For the
result to be False
, the container must be finite; True
, however,
results from a True
value finitely far from the left end.
Examples
Basic usage:
>>>
or []
False
>>>
or [True]
True
>>>
or [False]
False
>>>
or [True, True, False]
True
>>>
or (True : repeat False) -- Infinite list [True,False,False,False,...
True
>>>
or (repeat False)
* Hangs forever *
notElem :: (Foldable t, Eq a) => a -> t a -> Bool infix 4 #
notElem
is the negation of elem
.
Examples
Basic usage:
>>>
3 `notElem` []
True
>>>
3 `notElem` [1,2]
True
>>>
3 `notElem` [1,2,3,4,5]
False
For infinite structures, notElem
terminates if the value exists at a
finite distance from the left side of the structure:
>>>
3 `notElem` [1..]
False
>>>
3 `notElem` ([4..] ++ [3])
* Hangs forever *
minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a #
The least element of a non-empty structure with respect to the given comparison function.
Examples
Basic usage:
>>>
minimumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"!"
WARNING: This function is partial for possibly-empty structures like lists.
maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a #
The largest element of a non-empty structure with respect to the given comparison function.
Examples
Basic usage:
>>>
maximumBy (compare `on` length) ["Hello", "World", "!", "Longest", "bar"]
"Longest"
WARNING: This function is partial for possibly-empty structures like lists.
for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f () #
for_
is traverse_
with its arguments flipped. For a version
that doesn't ignore the results see for
. This
is forM_
generalised to Applicative
actions.
for_
is just like forM_
, but generalised to Applicative
actions.
Examples
Basic usage:
>>>
for_ [1..4] print
1 2 3 4
foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b #
Right-to-left monadic fold over the elements of a structure.
Given a structure t
with elements (a, b, c, ..., x, y)
, the result of
a fold with an operator function f
is equivalent to:
foldrM f z t = do yy <- f y z xx <- f x yy ... bb <- f b cc aa <- f a bb return aa -- Just @return z@ when the structure is empty
For a Monad m
, given two functions f1 :: a -> m b
and f2 :: b -> m c
,
their Kleisli composition (f1 >=> f2) :: a -> m c
is defined by:
(f1 >=> f2) a = f1 a >>= f2
Another way of thinking about foldrM
is that it amounts to an application
to z
of a Kleisli composition:
foldrM f z t = f y >=> f x >=> ... >=> f b >=> f a $ z
The monadic effects of foldrM
are sequenced from right to left, and e.g.
folds of infinite lists will diverge.
If at some step the bind operator (
short-circuits (as with, e.g.,
>>=
)mzero
in a MonadPlus
), the evaluated effects will be from a tail of the
element sequence. If you want to evaluate the monadic effects in
left-to-right order, or perhaps be able to short-circuit after an initial
sequence of elements, you'll need to use foldlM
instead.
If the monadic effects don't short-circuit, the outermost application of
f
is to the leftmost element a
, so that, ignoring effects, the result
looks like a right fold:
a `f` (b `f` (c `f` (... (x `f` (y `f` z))))).
Examples
Basic usage:
>>>
let f i acc = do { print i ; return $ i : acc }
>>>
foldrM f [] [0..3]
3 2 1 0 [0,1,2,3]
foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
Left-to-right monadic fold over the elements of a structure.
Given a structure t
with elements (a, b, ..., w, x, y)
, the result of
a fold with an operator function f
is equivalent to:
foldlM f z t = do aa <- f z a bb <- f aa b ... xx <- f ww x yy <- f xx y return yy -- Just @return z@ when the structure is empty
For a Monad m
, given two functions f1 :: a -> m b
and f2 :: b -> m c
,
their Kleisli composition (f1 >=> f2) :: a -> m c
is defined by:
(f1 >=> f2) a = f1 a >>= f2
Another way of thinking about foldlM
is that it amounts to an application
to z
of a Kleisli composition:
foldlM f z t = flip f a >=> flip f b >=> ... >=> flip f x >=> flip f y $ z
The monadic effects of foldlM
are sequenced from left to right.
If at some step the bind operator (
short-circuits (as with, e.g.,
>>=
)mzero
in a MonadPlus
), the evaluated effects will be from an initial
segment of the element sequence. If you want to evaluate the monadic
effects in right-to-left order, or perhaps be able to short-circuit after
processing a tail of the sequence of elements, you'll need to use foldrM
instead.
If the monadic effects don't short-circuit, the outermost application of
f
is to the rightmost element y
, so that, ignoring effects, the result
looks like a left fold:
((((z `f` a) `f` b) ... `f` w) `f` x) `f` y
Examples
Basic usage:
>>>
let f a e = do { print e ; return $ e : a }
>>>
foldlM f [] [0..3]
0 1 2 3 [3,2,1,0]
concatMap :: Foldable t => (a -> [b]) -> t a -> [b] #
Map a function over all the elements of a container and concatenate the resulting lists.
Examples
Basic usage:
>>>
concatMap (take 3) [[1..], [10..], [100..], [1000..]]
[1,2,3,10,11,12,100,101,102,1000,1001,1002]
>>>
concatMap (take 3) (Just [1..])
[1,2,3]
concat :: Foldable t => t [a] -> [a] #
The concatenation of all the elements of a container of lists.
Examples
Basic usage:
>>>
concat (Just [1, 2, 3])
[1,2,3]
>>>
concat (Left 42)
[]
>>>
concat [[1, 2, 3], [4, 5], [6], []]
[1,2,3,4,5,6]
asum :: (Foldable t, Alternative f) => t (f a) -> f a #
The sum of a collection of actions, generalizing concat
.
asum
is just like msum
, but generalised to Alternative
.
Examples
Basic usage:
>>>
asum [Just "Hello", Nothing, Just "World"]
Just "Hello"
any :: Foldable t => (a -> Bool) -> t a -> Bool #
Determines whether any element of the structure satisfies the predicate.
Examples
Basic usage:
>>>
any (> 3) []
False
>>>
any (> 3) [1,2]
False
>>>
any (> 3) [1,2,3,4,5]
True
>>>
any (> 3) [1..]
True
>>>
any (> 3) [0, -1..]
* Hangs forever *
and :: Foldable t => t Bool -> Bool #
and
returns the conjunction of a container of Bools. For the
result to be True
, the container must be finite; False
, however,
results from a False
value finitely far from the left end.
Examples
Basic usage:
>>>
and []
True
>>>
and [True]
True
>>>
and [False]
False
>>>
and [True, True, False]
False
>>>
and (False : repeat True) -- Infinite list [False,True,True,True,...
False
>>>
and (repeat True)
* Hangs forever *
all :: Foldable t => (a -> Bool) -> t a -> Bool #
Determines whether all elements of the structure satisfy the predicate.
Examples
Basic usage:
>>>
all (> 3) []
True
>>>
all (> 3) [1,2]
False
>>>
all (> 3) [1,2,3,4,5]
False
>>>
all (> 3) [1..]
False
>>>
all (> 3) [4..]
* Hangs forever *
zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h] #
words
breaks a string up into a list of words, which were delimited
by white space.
>>>
words "Lorem ipsum\ndolor"
["Lorem","ipsum","dolor"]
union :: Eq a => [a] -> [a] -> [a] #
The union
function returns the list union of the two lists.
For example,
>>>
"dog" `union` "cow"
"dogcw"
Duplicates, and elements of the first list, are removed from the
the second list, but if the first list contains duplicates, so will
the result.
It is a special case of unionBy
, which allows the programmer to supply
their own equality test.
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
A simple use of unfoldr:
>>>
unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10
[10,9,8,7,6,5,4,3,2,1]
The transpose
function transposes the rows and columns of its argument.
For example,
>>>
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]]
subsequences :: [a] -> [[a]] #
The subsequences
function returns the list of all subsequences of the argument.
>>>
subsequences "abc"
["","a","b","ab","c","ac","bc","abc"]
stripPrefix :: Eq a => [a] -> [a] -> Maybe [a] #
\(\mathcal{O}(\min(m,n))\). The stripPrefix
function drops the given
prefix from a list. It returns Nothing
if the list did not start with the
prefix given, or Just
the list after the prefix, if it does.
>>>
stripPrefix "foo" "foobar"
Just "bar"
>>>
stripPrefix "foo" "foo"
Just ""
>>>
stripPrefix "foo" "barfoo"
Nothing
>>>
stripPrefix "foo" "barfoobaz"
Nothing
sortOn :: Ord b => (a -> b) -> [a] -> [a] #
Sort a list by comparing the results of a key function applied to each
element. sortOn f
is equivalent to sortBy (comparing f)
, but has the
performance advantage of only evaluating 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.
>>>
sortOn fst [(2, "world"), (4, "!"), (1, "Hello")]
[(1,"Hello"),(2,"world"),(4,"!")]
Since: base-4.8.0.0
permutations :: [a] -> [[a]] #
The permutations
function returns the list of all permutations of the argument.
>>>
permutations "abc"
["abc","bac","cba","bca","cab","acb"]
partition :: (a -> Bool) -> [a] -> ([a], [a]) #
The partition
function takes a predicate and a list, and returns
the pair of lists of elements which do and do not satisfy the
predicate, respectively; i.e.,
partition p xs == (filter p xs, filter (not . p) xs)
>>>
partition (`elem` "aeiou") "Hello World!"
("eoo","Hll Wrld!")
\(\mathcal{O}(n^2)\). The nub
function removes duplicate elements from a
list. In particular, it keeps only the first occurrence of each element. (The
name nub
means `essence'.) It is a special case of nubBy
, which allows
the programmer to supply their own equality test.
>>>
nub [1,2,3,4,3,2,1,2,4,3,5]
[1,2,3,4,5]
lines
breaks a string up into a list of strings at newline
characters. The resulting strings do not contain newlines.
Note that after splitting the string at newline characters, the last part of the string is considered a line even if it doesn't end with a newline. For example,
>>>
lines ""
[]
>>>
lines "\n"
[""]
>>>
lines "one"
["one"]
>>>
lines "one\n"
["one"]
>>>
lines "one\n\n"
["one",""]
>>>
lines "one\ntwo"
["one","two"]
>>>
lines "one\ntwo\n"
["one","two"]
Thus
contains at least as many elements as newlines in lines
ss
.
isSuffixOf :: Eq a => [a] -> [a] -> Bool #
The isSuffixOf
function takes two lists and returns True
iff
the first list is a suffix of the second. The second list must be
finite.
>>>
"ld!" `isSuffixOf` "Hello World!"
True
>>>
"World" `isSuffixOf` "Hello World!"
False
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.
>>>
"Hello" `isPrefixOf` "Hello World!"
True
>>>
"Hello" `isPrefixOf` "Wello Horld!"
False
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. For
example,
>>>
intersperse ',' "abcde"
"a,b,c,d,e"
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] #
The intersectBy
function is the non-overloaded version of intersect
.
intersect :: Eq a => [a] -> [a] -> [a] #
The intersect
function takes the list intersection of two lists.
For example,
>>>
[1,2,3,4] `intersect` [2,4,6,8]
[2,4]
If the first list contains duplicates, so will the result.
>>>
[1,2,2,3,4] `intersect` [6,4,4,2]
[2,2,4]
It is a special case of intersectBy
, which allows the programmer to
supply their own equality test. If the element is found in both the first
and the second list, the element from the first list will be used.
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.
>>>
intercalate ", " ["Lorem", "ipsum", "dolor"]
"Lorem, ipsum, dolor"
insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a] #
\(\mathcal{O}(n)\). The non-overloaded version of insert
.
insert :: Ord a => a -> [a] -> [a] #
\(\mathcal{O}(n)\). The insert
function takes an element and a list and
inserts the element into the list at the first position where it is less than
or equal to the next element. In particular, if the list is sorted before the
call, the result will also be sorted. It is a special case of insertBy
,
which allows the programmer to supply their own comparison function.
>>>
insert 4 [1,2,3,5,6,7]
[1,2,3,4,5,6,7]
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 contains only equal elements. For example,
>>>
group "Mississippi"
["M","i","ss","i","ss","i","pp","i"]
It is a special case of groupBy
, which allows the programmer to supply
their own equality test.
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.
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.
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
.
>>>
genericLength [1, 2, 3] :: Int
3>>>
genericLength [1, 2, 3] :: Float
3.0
genericIndex :: Integral i => [a] -> i -> a #
The genericIndex
function is an overloaded version of !!
, which
accepts any Integral
value as the index.
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.
findIndices :: (a -> Bool) -> [a] -> [Int] #
The findIndices
function extends findIndex
, by returning the
indices of all elements satisfying the predicate, in ascending order.
>>>
findIndices (`elem` "aeiou") "Hello World!"
[1,4,7]
elemIndices :: Eq a => a -> [a] -> [Int] #
The elemIndices
function extends elemIndex
, by returning the
indices of all elements equal to the query element, in ascending order.
>>>
elemIndices 'o' "Hello World"
[4,7]
dropWhileEnd :: (a -> Bool) -> [a] -> [a] #
The dropWhileEnd
function drops the largest suffix of a list
in which the given predicate holds for all elements. For example:
>>>
dropWhileEnd isSpace "foo\n"
"foo"
>>>
dropWhileEnd isSpace "foo bar"
"foo bar"
dropWhileEnd isSpace ("foo\n" ++ undefined) == "foo" ++ undefined
Since: base-4.5.0.0
deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] #
The deleteFirstsBy
function takes a predicate and two lists and
returns the first list with the first occurrence of each element of
the second list removed.
(\\) :: Eq a => [a] -> [a] -> [a] infix 5 #
The \\
function is list difference (non-associative).
In the result of xs
\\
ys
, the first occurrence of each element of
ys
in turn (if any) has been removed from xs
. Thus
(xs ++ ys) \\ xs == ys.
>>>
"Hello World!" \\ "ell W"
"Hoorld!"
It is a special case of deleteFirstsBy
, which allows the programmer
to supply their own equality test.
Maybe monoid returning the rightmost non-Nothing value.
is isomorphic to Last
a
, and thus to
Dual
(First
a)Dual
(Alt
Maybe
a)
>>>
getLast (Last (Just "hello") <> Last Nothing <> Last (Just "world"))
Just "world"
Instances
MonadFix Last | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
Foldable Last | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Last m -> m # foldMap :: Monoid m => (a -> m) -> Last a -> m # foldMap' :: Monoid m => (a -> m) -> Last a -> m # foldr :: (a -> b -> b) -> b -> Last a -> b # foldr' :: (a -> b -> b) -> b -> Last a -> b # foldl :: (b -> a -> b) -> b -> Last a -> b # foldl' :: (b -> a -> b) -> b -> Last a -> b # foldr1 :: (a -> a -> a) -> Last a -> a # foldl1 :: (a -> a -> a) -> Last a -> a # elem :: Eq a => a -> Last a -> Bool # maximum :: Ord a => Last a -> a # | |
Traversable Last | Since: base-4.8.0.0 |
Applicative Last | Since: base-4.8.0.0 |
Functor Last | Since: base-4.8.0.0 |
Monad Last | Since: base-4.8.0.0 |
NFData1 Last | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Monoid (Last a) | Since: base-2.1 |
Semigroup (Last a) | Since: base-4.9.0.0 |
Generic (Last a) | |
Read a => Read (Last a) | Since: base-2.1 |
Show a => Show (Last a) | Since: base-2.1 |
Default (Last a) | |
Defined in Data.Default.Class | |
NFData a => NFData (Last a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (Last a) | Since: base-2.1 |
Ord a => Ord (Last a) | Since: base-2.1 |
Generic1 Last | |
type Rep (Last a) | Since: base-4.7.0.0 |
Defined in Data.Monoid | |
type Rep1 Last | Since: base-4.7.0.0 |
Defined in Data.Monoid |
Maybe monoid returning the leftmost non-Nothing value.
is isomorphic to First
a
, but precedes it
historically.Alt
Maybe
a
>>>
getFirst (First (Just "hello") <> First Nothing <> First (Just "world"))
Just "hello"
Instances
MonadFix First | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
Foldable First | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => First m -> m # foldMap :: Monoid m => (a -> m) -> First a -> m # foldMap' :: Monoid m => (a -> m) -> First a -> m # foldr :: (a -> b -> b) -> b -> First a -> b # foldr' :: (a -> b -> b) -> b -> First a -> b # foldl :: (b -> a -> b) -> b -> First a -> b # foldl' :: (b -> a -> b) -> b -> First a -> b # foldr1 :: (a -> a -> a) -> First a -> a # foldl1 :: (a -> a -> a) -> First a -> a # elem :: Eq a => a -> First a -> Bool # maximum :: Ord a => First a -> a # minimum :: Ord a => First a -> a # | |
Traversable First | Since: base-4.8.0.0 |
Applicative First | Since: base-4.8.0.0 |
Functor First | Since: base-4.8.0.0 |
Monad First | Since: base-4.8.0.0 |
NFData1 First | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Monoid (First a) | Since: base-2.1 |
Semigroup (First a) | Since: base-4.9.0.0 |
Generic (First a) | |
Read a => Read (First a) | Since: base-2.1 |
Show a => Show (First a) | Since: base-2.1 |
Default (First a) | |
Defined in Data.Default.Class | |
NFData a => NFData (First a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (First a) | Since: base-2.1 |
Ord a => Ord (First a) | Since: base-2.1 |
Generic1 First | |
type Rep (First a) | Since: base-4.7.0.0 |
Defined in Data.Monoid | |
type Rep1 First | Since: base-4.7.0.0 |
Defined in Data.Monoid |
newtype Ap (f :: k -> Type) (a :: k) #
This data type witnesses the lifting of a Monoid
into an
Applicative
pointwise.
Since: base-4.12.0.0
Instances
Generic1 (Ap f :: k -> Type) | |
MonadFail f => MonadFail (Ap f) | Since: base-4.12.0.0 |
Defined in Data.Monoid | |
MonadFix f => MonadFix (Ap f) | Since: base-4.12.0.0 |
Defined in Control.Monad.Fix | |
Foldable f => Foldable (Ap f) | Since: base-4.12.0.0 |
Defined in Data.Foldable fold :: Monoid m => Ap f m -> m # foldMap :: Monoid m => (a -> m) -> Ap f a -> m # foldMap' :: Monoid m => (a -> m) -> Ap f a -> m # foldr :: (a -> b -> b) -> b -> Ap f a -> b # foldr' :: (a -> b -> b) -> b -> Ap f a -> b # foldl :: (b -> a -> b) -> b -> Ap f a -> b # foldl' :: (b -> a -> b) -> b -> Ap f a -> b # foldr1 :: (a -> a -> a) -> Ap f a -> a # foldl1 :: (a -> a -> a) -> Ap f a -> a # elem :: Eq a => a -> Ap f a -> Bool # maximum :: Ord a => Ap f a -> a # | |
Traversable f => Traversable (Ap f) | Since: base-4.12.0.0 |
Alternative f => Alternative (Ap f) | Since: base-4.12.0.0 |
Applicative f => Applicative (Ap f) | Since: base-4.12.0.0 |
Functor f => Functor (Ap f) | Since: base-4.12.0.0 |
Monad f => Monad (Ap f) | Since: base-4.12.0.0 |
MonadPlus f => MonadPlus (Ap f) | Since: base-4.12.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0 |
(Applicative f, Semigroup a) => Semigroup (Ap f a) | Since: base-4.12.0.0 |
(Applicative f, Bounded a) => Bounded (Ap f a) | Since: base-4.12.0.0 |
Enum (f a) => Enum (Ap f a) | Since: base-4.12.0.0 |
Defined in Data.Monoid | |
Generic (Ap f a) | |
(Applicative f, Num a) => Num (Ap f a) | Note that even if the underlying Commutativity:
Additive inverse:
Distributivity:
Since: base-4.12.0.0 |
Read (f a) => Read (Ap f a) | Since: base-4.12.0.0 |
Show (f a) => Show (Ap f a) | Since: base-4.12.0.0 |
Eq (f a) => Eq (Ap f a) | Since: base-4.12.0.0 |
Ord (f a) => Ord (Ap f a) | Since: base-4.12.0.0 |
type Rep1 (Ap f :: k -> Type) | Since: base-4.12.0.0 |
Defined in Data.Monoid | |
type Rep (Ap f a) | Since: base-4.12.0.0 |
Defined in Data.Monoid |
Monoid under addition.
>>>
getSum (Sum 1 <> Sum 2 <> mempty)
3
Instances
MonadFix Sum | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
Foldable Sum | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Sum m -> m # foldMap :: Monoid m => (a -> m) -> Sum a -> m # foldMap' :: Monoid m => (a -> m) -> Sum a -> m # foldr :: (a -> b -> b) -> b -> Sum a -> b # foldr' :: (a -> b -> b) -> b -> Sum a -> b # foldl :: (b -> a -> b) -> b -> Sum a -> b # foldl' :: (b -> a -> b) -> b -> Sum a -> b # foldr1 :: (a -> a -> a) -> Sum a -> a # foldl1 :: (a -> a -> a) -> Sum a -> a # elem :: Eq a => a -> Sum a -> Bool # maximum :: Ord a => Sum a -> a # | |
Traversable Sum | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Functor Sum | Since: base-4.8.0.0 |
Monad Sum | Since: base-4.8.0.0 |
NFData1 Sum | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Num a => Monoid (Sum a) | Since: base-2.1 |
Num a => Semigroup (Sum a) | Since: base-4.9.0.0 |
Bounded a => Bounded (Sum a) | Since: base-2.1 |
Generic (Sum a) | |
Num a => Num (Sum a) | Since: base-4.7.0.0 |
Read a => Read (Sum a) | Since: base-2.1 |
Show a => Show (Sum a) | Since: base-2.1 |
Num a => Default (Sum a) | |
Defined in Data.Default.Class | |
NFData a => NFData (Sum a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (Sum a) | Since: base-2.1 |
Ord a => Ord (Sum a) | Since: base-2.1 |
Generic1 Sum | |
type Rep (Sum a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep1 Sum | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
Monoid under multiplication.
>>>
getProduct (Product 3 <> Product 4 <> mempty)
12
Product | |
|
Instances
MonadFix Product | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
Foldable Product | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Product m -> m # foldMap :: Monoid m => (a -> m) -> Product a -> m # foldMap' :: Monoid m => (a -> m) -> Product a -> m # foldr :: (a -> b -> b) -> b -> Product a -> b # foldr' :: (a -> b -> b) -> b -> Product a -> b # foldl :: (b -> a -> b) -> b -> Product a -> b # foldl' :: (b -> a -> b) -> b -> Product a -> b # foldr1 :: (a -> a -> a) -> Product a -> a # foldl1 :: (a -> a -> a) -> Product a -> a # elem :: Eq a => a -> Product a -> Bool # maximum :: Ord a => Product a -> a # minimum :: Ord a => Product a -> a # | |
Traversable Product | Since: base-4.8.0.0 |
Applicative Product | Since: base-4.8.0.0 |
Functor Product | Since: base-4.8.0.0 |
Monad Product | Since: base-4.8.0.0 |
NFData1 Product | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Num a => Monoid (Product a) | Since: base-2.1 |
Num a => Semigroup (Product a) | Since: base-4.9.0.0 |
Bounded a => Bounded (Product a) | Since: base-2.1 |
Generic (Product a) | |
Num a => Num (Product a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
Read a => Read (Product a) | Since: base-2.1 |
Show a => Show (Product a) | Since: base-2.1 |
Num a => Default (Product a) | |
Defined in Data.Default.Class | |
NFData a => NFData (Product a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (Product a) | Since: base-2.1 |
Ord a => Ord (Product a) | Since: base-2.1 |
Defined in Data.Semigroup.Internal | |
Generic1 Product | |
type Rep (Product a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep1 Product | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
The monoid of endomorphisms under composition.
>>>
let computation = Endo ("Hello, " ++) <> Endo (++ "!")
>>>
appEndo computation "Haskell"
"Hello, Haskell!"
The dual of a Monoid
, obtained by swapping the arguments of mappend
.
>>>
getDual (mappend (Dual "Hello") (Dual "World"))
"WorldHello"
Instances
MonadFix Dual | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
Foldable Dual | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Dual m -> m # foldMap :: Monoid m => (a -> m) -> Dual a -> m # foldMap' :: Monoid m => (a -> m) -> Dual a -> m # foldr :: (a -> b -> b) -> b -> Dual a -> b # foldr' :: (a -> b -> b) -> b -> Dual a -> b # foldl :: (b -> a -> b) -> b -> Dual a -> b # foldl' :: (b -> a -> b) -> b -> Dual a -> b # foldr1 :: (a -> a -> a) -> Dual a -> a # foldl1 :: (a -> a -> a) -> Dual a -> a # elem :: Eq a => a -> Dual a -> Bool # maximum :: Ord a => Dual a -> a # | |
Traversable Dual | Since: base-4.8.0.0 |
Applicative Dual | Since: base-4.8.0.0 |
Functor Dual | Since: base-4.8.0.0 |
Monad Dual | Since: base-4.8.0.0 |
NFData1 Dual | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Semigroup a => Semigroup (Dual a) | Since: base-4.9.0.0 |
Bounded a => Bounded (Dual a) | Since: base-2.1 |
Generic (Dual a) | |
Read a => Read (Dual a) | Since: base-2.1 |
Show a => Show (Dual a) | Since: base-2.1 |
Default a => Default (Dual a) | |
Defined in Data.Default.Class | |
NFData a => NFData (Dual a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (Dual a) | Since: base-2.1 |
Ord a => Ord (Dual a) | Since: base-2.1 |
Generic1 Dual | |
type Rep (Dual a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep1 Dual | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
Boolean monoid under disjunction (||
).
>>>
getAny (Any True <> mempty <> Any False)
True
>>>
getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8]))
True
Instances
Monoid Any | Since: base-2.1 |
Semigroup Any | Since: base-4.9.0.0 |
Bounded Any | Since: base-2.1 |
Generic Any | |
Read Any | Since: base-2.1 |
Show Any | Since: base-2.1 |
Default Any | |
Defined in Data.Default.Class | |
NFData Any | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq Any | Since: base-2.1 |
Ord Any | Since: base-2.1 |
type Rep Any | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
newtype Alt (f :: k -> Type) (a :: k) #
Monoid under <|>
.
>>>
getAlt (Alt (Just 12) <> Alt (Just 24))
Just 12
>>>
getAlt $ Alt Nothing <> Alt (Just 24)
Just 24
Since: base-4.8.0.0
Instances
Generic1 (Alt f :: k -> Type) | |
MonadFix f => MonadFix (Alt f) | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
Foldable f => Foldable (Alt f) | Since: base-4.12.0.0 |
Defined in Data.Foldable fold :: Monoid m => Alt f m -> m # foldMap :: Monoid m => (a -> m) -> Alt f a -> m # foldMap' :: Monoid m => (a -> m) -> Alt f a -> m # foldr :: (a -> b -> b) -> b -> Alt f a -> b # foldr' :: (a -> b -> b) -> b -> Alt f a -> b # foldl :: (b -> a -> b) -> b -> Alt f a -> b # foldl' :: (b -> a -> b) -> b -> Alt f a -> b # foldr1 :: (a -> a -> a) -> Alt f a -> a # foldl1 :: (a -> a -> a) -> Alt f a -> a # elem :: Eq a => a -> Alt f a -> Bool # maximum :: Ord a => Alt f a -> a # minimum :: Ord a => Alt f a -> a # | |
Traversable f => Traversable (Alt f) | Since: base-4.12.0.0 |
Alternative f => Alternative (Alt f) | Since: base-4.8.0.0 |
Applicative f => Applicative (Alt f) | Since: base-4.8.0.0 |
Functor f => Functor (Alt f) | Since: base-4.8.0.0 |
Monad f => Monad (Alt f) | Since: base-4.8.0.0 |
MonadPlus f => MonadPlus (Alt f) | Since: base-4.8.0.0 |
Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0 |
Alternative f => Semigroup (Alt f a) | Since: base-4.9.0.0 |
Enum (f a) => Enum (Alt f a) | Since: base-4.8.0.0 |
Generic (Alt f a) | |
Num (f a) => Num (Alt f a) | Since: base-4.8.0.0 |
Read (f a) => Read (Alt f a) | Since: base-4.8.0.0 |
Show (f a) => Show (Alt f a) | Since: base-4.8.0.0 |
Eq (f a) => Eq (Alt f a) | Since: base-4.8.0.0 |
Ord (f a) => Ord (Alt f a) | Since: base-4.8.0.0 |
type Rep1 (Alt f :: k -> Type) | Since: base-4.8.0.0 |
Defined in Data.Semigroup.Internal | |
type Rep (Alt f a) | Since: base-4.8.0.0 |
Defined in Data.Semigroup.Internal |
Boolean monoid under conjunction (&&
).
>>>
getAll (All True <> mempty <> All False)
False
>>>
getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8]))
False
Instances
Monoid All | Since: base-2.1 |
Semigroup All | Since: base-4.9.0.0 |
Bounded All | Since: base-2.1 |
Generic All | |
Read All | Since: base-2.1 |
Show All | Since: base-2.1 |
Default All | |
Defined in Data.Default.Class | |
NFData All | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq All | Since: base-2.1 |
Ord All | Since: base-2.1 |
type Rep All | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal |
isSeparator :: Char -> Bool #
Selects Unicode space and separator characters.
This function returns True
if its argument has one of the
following GeneralCategory
s, or False
otherwise:
These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Separator".
Examples
Basic usage:
>>>
isSeparator 'a'
False>>>
isSeparator '6'
False>>>
isSeparator ' '
True
Warning: newlines and tab characters are not considered separators.
>>>
isSeparator '\n'
False>>>
isSeparator '\t'
False
But some more exotic characters are (like HTML's
):
>>>
isSeparator '\160'
True
Selects Unicode numeric characters, including digits from various scripts, Roman numerals, et cetera.
This function returns True
if its argument has one of the
following GeneralCategory
s, or False
otherwise:
These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Number".
Examples
Basic usage:
>>>
isNumber 'a'
False>>>
isNumber '%'
False>>>
isNumber '3'
True
ASCII '0'
through '9'
are all numbers:
>>>
and $ map isNumber ['0'..'9']
True
Unicode Roman numerals are "numbers" as well:
>>>
isNumber 'Ⅸ'
True
Selects Unicode mark characters, for example accents and the like, which combine with preceding characters.
This function returns True
if its argument has one of the
following GeneralCategory
s, or False
otherwise:
These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Mark".
Examples
Basic usage:
>>>
isMark 'a'
False>>>
isMark '0'
False
Combining marks such as accent characters usually need to follow another character before they become printable:
>>>
map isMark "ò"
[False,True]
Puns are not necessarily supported:
>>>
isMark '✓'
False
Selects alphabetic Unicode characters (lower-case, upper-case and
title-case letters, plus letters of caseless scripts and
modifiers letters). This function is equivalent to
isAlpha
.
This function returns True
if its argument has one of the
following GeneralCategory
s, or False
otherwise:
These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Letter".
Examples
Basic usage:
>>>
isLetter 'a'
True>>>
isLetter 'A'
True>>>
isLetter 'λ'
True>>>
isLetter '0'
False>>>
isLetter '%'
False>>>
isLetter '♥'
False>>>
isLetter '\31'
False
Ensure that isLetter
and isAlpha
are equivalent.
>>>
let chars = [(chr 0)..]
>>>
let letters = map isLetter chars
>>>
let alphas = map isAlpha chars
>>>
letters == alphas
True
digitToInt :: Char -> Int #
Convert a single digit Char
to the corresponding Int
. This
function fails unless its argument satisfies isHexDigit
, but
recognises both upper- and lower-case hexadecimal digits (that
is, '0'
..'9'
, 'a'
..'f'
, 'A'
..'F'
).
Examples
Characters '0'
through '9'
are converted properly to
0..9
:
>>>
map digitToInt ['0'..'9']
[0,1,2,3,4,5,6,7,8,9]
Both upper- and lower-case 'A'
through 'F'
are converted
as well, to 10..15
.
>>>
map digitToInt ['a'..'f']
[10,11,12,13,14,15]>>>
map digitToInt ['A'..'F']
[10,11,12,13,14,15]
Anything else throws an exception:
>>>
digitToInt 'G'
*** Exception: Char.digitToInt: not a digit 'G'>>>
digitToInt '♥'
*** Exception: Char.digitToInt: not a digit '\9829'
readLitChar :: ReadS Char #
Read a string representation of a character, using Haskell source-language escape conventions, and convert it to the character that it encodes. For example:
readLitChar "\\nHello" = [('\n', "Hello")]
lexLitChar :: ReadS String #
Read a string representation of a character, using Haskell source-language escape conventions. For example:
lexLitChar "\\nHello" = [("\\n", "Hello")]
data GeneralCategory #
Unicode General Categories (column 2 of the UnicodeData table) in the order they are listed in the Unicode standard (the Unicode Character Database, in particular).
Examples
Basic usage:
>>>
:t OtherLetter
OtherLetter :: GeneralCategory
Eq
instance:
>>>
UppercaseLetter == UppercaseLetter
True>>>
UppercaseLetter == LowercaseLetter
False
Ord
instance:
>>>
NonSpacingMark <= MathSymbol
True
Enum
instance:
>>>
enumFromTo ModifierLetter SpacingCombiningMark
[ModifierLetter,OtherLetter,NonSpacingMark,SpacingCombiningMark]
Read
instance:
>>>
read "DashPunctuation" :: GeneralCategory
DashPunctuation>>>
read "17" :: GeneralCategory
*** Exception: Prelude.read: no parse
Show
instance:
>>>
show EnclosingMark
"EnclosingMark"
Bounded
instance:
>>>
minBound :: GeneralCategory
UppercaseLetter>>>
maxBound :: GeneralCategory
NotAssigned
Ix
instance:
>>>
import Data.Ix ( index )
>>>
index (OtherLetter,Control) FinalQuote
12>>>
index (OtherLetter,Control) Format
*** Exception: Error in array index
UppercaseLetter | Lu: Letter, Uppercase |
LowercaseLetter | Ll: Letter, Lowercase |
TitlecaseLetter | Lt: Letter, Titlecase |
ModifierLetter | Lm: Letter, Modifier |
OtherLetter | Lo: Letter, Other |
NonSpacingMark | Mn: Mark, Non-Spacing |
SpacingCombiningMark | Mc: Mark, Spacing Combining |
EnclosingMark | Me: Mark, Enclosing |
DecimalNumber | Nd: Number, Decimal |
LetterNumber | Nl: Number, Letter |
OtherNumber | No: Number, Other |
ConnectorPunctuation | Pc: Punctuation, Connector |
DashPunctuation | Pd: Punctuation, Dash |
OpenPunctuation | Ps: Punctuation, Open |
ClosePunctuation | Pe: Punctuation, Close |
InitialQuote | Pi: Punctuation, Initial quote |
FinalQuote | Pf: Punctuation, Final quote |
OtherPunctuation | Po: Punctuation, Other |
MathSymbol | Sm: Symbol, Math |
CurrencySymbol | Sc: Symbol, Currency |
ModifierSymbol | Sk: Symbol, Modifier |
OtherSymbol | So: Symbol, Other |
Space | Zs: Separator, Space |
LineSeparator | Zl: Separator, Line |
ParagraphSeparator | Zp: Separator, Paragraph |
Control | Cc: Other, Control |
Format | Cf: Other, Format |
Surrogate | Cs: Other, Surrogate |
PrivateUse | Co: Other, Private Use |
NotAssigned | Cn: Other, Not Assigned |
Instances
Convert a letter to the corresponding upper-case letter, if any. Any other character is returned unchanged.
Convert a letter to the corresponding title-case or upper-case letter, if any. (Title case differs from upper case only for a small number of ligature letters.) Any other character is returned unchanged.
Convert a letter to the corresponding lower-case letter, if any. Any other character is returned unchanged.
Selects upper-case or title-case alphabetic Unicode characters (letters). Title case is used by a small number of letter ligatures like the single-character form of Lj.
Selects Unicode symbol characters, including mathematical and currency symbols.
This function returns True
if its argument has one of the
following GeneralCategory
s, or False
otherwise:
These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Symbol".
Examples
Basic usage:
>>>
isSymbol 'a'
False>>>
isSymbol '6'
False>>>
isSymbol '='
True
The definition of "math symbol" may be a little counter-intuitive depending on one's background:
>>>
isSymbol '+'
True>>>
isSymbol '-'
False
Returns True
for any Unicode space character, and the control
characters \t
, \n
, \r
, \f
, \v
.
isPunctuation :: Char -> Bool #
Selects Unicode punctuation characters, including various kinds of connectors, brackets and quotes.
This function returns True
if its argument has one of the
following GeneralCategory
s, or False
otherwise:
ConnectorPunctuation
DashPunctuation
OpenPunctuation
ClosePunctuation
InitialQuote
FinalQuote
OtherPunctuation
These classes are defined in the Unicode Character Database, part of the Unicode standard. The same document defines what is and is not a "Punctuation".
Examples
Basic usage:
>>>
isPunctuation 'a'
False>>>
isPunctuation '7'
False>>>
isPunctuation '♥'
False>>>
isPunctuation '"'
True>>>
isPunctuation '?'
True>>>
isPunctuation '—'
True
Selects printable Unicode characters (letters, numbers, marks, punctuation, symbols and spaces).
isOctDigit :: Char -> Bool #
Selects ASCII octal digits, i.e. '0'
..'7'
.
Selects the first 256 characters of the Unicode character set, corresponding to the ISO 8859-1 (Latin-1) character set.
isHexDigit :: Char -> Bool #
Selects ASCII hexadecimal digits,
i.e. '0'
..'9'
, 'a'
..'f'
, 'A'
..'F'
.
Selects control characters, which are the non-printing characters of the Latin-1 subset of Unicode.
isAsciiUpper :: Char -> Bool #
isAsciiLower :: Char -> Bool #
Selects the first 128 characters of the Unicode character set, corresponding to the ASCII character set.
isAlphaNum :: Char -> Bool #
Selects alphabetic or numeric Unicode characters.
Note that numeric digits outside the ASCII range, as well as numeric
characters which aren't digits, are selected by this function but not by
isDigit
. Such characters may be part of identifiers but are not used by
the printer and reader to represent numbers.
Selects alphabetic Unicode characters (lower-case, upper-case and
title-case letters, plus letters of caseless scripts and modifiers letters).
This function is equivalent to isLetter
.
generalCategory :: Char -> GeneralCategory #
The Unicode general category of the character. This relies on the
Enum
instance of GeneralCategory
, which must remain in the
same order as the categories are presented in the Unicode
standard.
Examples
Basic usage:
>>>
generalCategory 'a'
LowercaseLetter>>>
generalCategory 'A'
UppercaseLetter>>>
generalCategory '0'
DecimalNumber>>>
generalCategory '%'
OtherPunctuation>>>
generalCategory '♥'
OtherSymbol>>>
generalCategory '\31'
Control>>>
generalCategory ' '
Space
showLitChar :: Char -> ShowS #
Convert a character to a string using only printable characters, using Haskell source-language escape conventions. For example:
showLitChar '\n' s = "\\n" ++ s
intToDigit :: Int -> Char #
zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d] #
The zipWith3
function takes a function which combines three
elements, as well as three lists and returns a list of the function applied
to corresponding elements, analogous to zipWith
.
It is capable of list fusion, but it is restricted to its
first list argument and its resulting list.
zipWith3 (,,) xs ys zs == zip3 xs ys zs zipWith3 f [x1,x2,x3..] [y1,y2,y3..] [z1,z2,z3..] == [f x1 y1 z1, f x2 y2 z2, f x3 y3 z3..]
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..]
For example,
is applied to two lists to produce the list of
corresponding sums:zipWith
(+)
>>>
zipWith (+) [1, 2, 3] [4, 5, 6]
[5,7,9]
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.
unzip :: [(a, b)] -> ([a], [b]) #
unzip
transforms a list of pairs into a list of first components
and a list of second components.
>>>
unzip []
([],[])>>>
unzip [(1, 'a'), (2, 'b')]
([1,2],"ab")
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
.
>>>
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
>>>
take 5 "Hello World!"
"Hello">>>
take 3 [1,2,3,4,5]
[1,2,3]>>>
take 3 [1,2]
[1,2]>>>
take 3 []
[]>>>
take (-1) [1,2]
[]>>>
take 0 [1,2]
[]
It is an instance of the more general genericTake
,
in which n
may be of any integral type.
\(\mathcal{O}(1)\). Extract the elements after the head of a list, which must be non-empty.
>>>
tail [1, 2, 3]
[2,3]>>>
tail [1]
[]>>>
tail []
*** Exception: Prelude.tail: empty list
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 6 "Hello World!"
("Hello ","World!")>>>
splitAt 3 [1,2,3,4,5]
([1,2,3],[4,5])>>>
splitAt 1 [1,2,3]
([1],[2,3])>>>
splitAt 3 [1,2,3]
([1,2,3],[])>>>
splitAt 4 [1,2,3]
([1,2,3],[])>>>
splitAt 0 [1,2,3]
([],[1,2,3])>>>
splitAt (-1) [1,2,3]
([],[1,2,3])
It is equivalent to (
when take
n xs, drop
n xs)n
is not _|_
(splitAt _|_ xs = _|_
).
splitAt
is an instance of the more general genericSplitAt
,
in which n
may be of any integral type.
span :: (a -> Bool) -> [a] -> ([a], [a]) #
span
, applied to a predicate p
and a list xs
, returns a tuple where
first element is longest prefix (possibly empty) of xs
of elements that
satisfy p
and second element is the remainder of the list:
>>>
span (< 3) [1,2,3,4,1,2,3,4]
([1,2],[3,4,1,2,3,4])>>>
span (< 9) [1,2,3]
([1,2,3],[])>>>
span (< 0) [1,2,3]
([],[1,2,3])
scanr1 :: (a -> a -> a) -> [a] -> [a] #
\(\mathcal{O}(n)\). scanr1
is a variant of scanr
that has no starting
value argument.
>>>
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
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.
>>>
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
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, ...]
>>>
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]>>>
scanl1 (+) [1..]
* Hangs forever *
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
>>>
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"]>>>
scanl (+) 0 [1..]
* Hangs forever *
reverse
xs
returns the elements of xs
in reverse order.
xs
must be finite.
>>>
reverse []
[]>>>
reverse [42]
[42]>>>
reverse [2,5,7]
[7,5,2]>>>
reverse [1..]
* Hangs forever *
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.
>>>
replicate 0 True
[]>>>
replicate (-1) True
[]>>>
replicate 4 True
[True,True,True,True]
repeat
x
is an infinite list, with x
the value of every element.
>>>
take 20 $ repeat 17
[17,17,17,17,17,17,17,17,17...
lookup :: Eq a => a -> [(a, b)] -> Maybe b #
\(\mathcal{O}(n)\). lookup
key assocs
looks up a key in an association
list.
>>>
lookup 2 []
Nothing>>>
lookup 2 [(1, "first")]
Nothing>>>
lookup 2 [(1, "first"), (2, "second"), (3, "third")]
Just "second"
\(\mathcal{O}(n)\). Extract the last element of a list, which must be finite and non-empty.
>>>
last [1, 2, 3]
3>>>
last [1..]
* Hangs forever *>>>
last []
*** Exception: Prelude.last: empty list
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), ...]
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 10 $ iterate not True
[True,False,True,False...>>>
take 10 $ iterate (+3) 42
[42,45,48,51,54,57,60,63...
\(\mathcal{O}(n)\). Return all the elements of a list except the last one. The list must be non-empty.
>>>
init [1, 2, 3]
[1,2]>>>
init [1]
[]>>>
init []
*** Exception: Prelude.init: empty list
\(\mathcal{O}(1)\). Extract the first element of a list, which must be non-empty.
>>>
head [1, 2, 3]
1>>>
head [1..]
1>>>
head []
*** Exception: Prelude.head: empty list
drop
n xs
returns the suffix of xs
after the first n
elements, or []
if n >=
.length
xs
>>>
drop 6 "Hello World!"
"World!">>>
drop 3 [1,2,3,4,5]
[4,5]>>>
drop 3 [1,2]
[]>>>
drop 3 []
[]>>>
drop (-1) [1,2]
[1,2]>>>
drop 0 [1,2]
[1,2]
It is an instance of the more general genericDrop
,
in which n
may be of any integral type.
cycle
ties a finite list into a circular one, or equivalently,
the infinite repetition of the original list. It is the identity
on infinite lists.
>>>
cycle []
*** Exception: Prelude.cycle: empty list>>>
take 20 $ cycle [42]
[42,42,42,42,42,42,42,42,42,42...>>>
take 20 $ cycle [2, 5, 7]
[2,5,7,2,5,7,2,5,7,2,5,7...
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 (> 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],[])
(!!) :: [a] -> Int -> a infixl 9 #
List index (subscript) operator, starting from 0.
It is an instance of the more general genericIndex
,
which takes an index of any integral type.
>>>
['a', 'b', 'c'] !! 0
'a'>>>
['a', 'b', 'c'] !! 2
'c'>>>
['a', 'b', 'c'] !! 3
*** Exception: Prelude.!!: index too large>>>
['a', 'b', 'c'] !! (-1)
*** Exception: Prelude.!!: negative index
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 Text.Read ( readMaybe )
>>>
sum $ maybeToList (readMaybe "3")
3>>>
sum $ maybeToList (readMaybe "")
0
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 Nothing
False
Read an integer from a string using readMaybe
. If we succeed,
return twice the integer; that is, apply (*2)
to it. If instead
we fail to parse an integer, return 0
by default:
>>>
import Text.Read ( readMaybe )
>>>
maybe 0 (*2) (readMaybe "5")
10>>>
maybe 0 (*2) (readMaybe "")
0
Apply show
to a Maybe Int
. If we have Just n
, we want to show
the underlying Int
n
. But if we have Nothing
, we return the
empty string instead of (for example) "Nothing":
>>>
maybe "" show (Just 5)
"5">>>
maybe "" show Nothing
""
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 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]
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]
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 Text.Read ( readMaybe )
>>>
fromMaybe 0 (readMaybe "5")
5>>>
fromMaybe 0 (readMaybe "")
0
fromJust :: HasCallStack => Maybe a -> a #
catMaybes :: [Maybe a] -> [a] #
The catMaybes
function takes a list of Maybe
s 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 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]
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 if-then-else 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: base-4.7.0.0
is the least fixed point of the function fix
ff
,
i.e. the least defined x
such that f x = x
.
For example, 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 5
120
This uses the fact that Haskell’s let
introduces recursive bindings. We can
rewrite this definition using fix
,
>>>
fix (\rec n -> if n <= 1 then 1 else n * rec (n-1)) 5
120
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.
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 Nothing
Nothing>>>
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
(<$>) :: 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
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an
Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "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
Int
String
:
>>>
Nothing $> "foo"
Nothing>>>
Just 90210 $> "foo"
Just "foo"
Replace the contents of an
with a constant Either
Int
Int
String
, 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
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
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
An associative operation. The default definition is
mplus = (<|>
)
Instances
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:
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
when :: Applicative f => Bool -> f () -> f () #
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.
liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2
).
liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r #
Promote a function to a monad, scanning the monadic arguments from left to right. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
liftA :: Applicative f => (a -> b) -> f a -> f b #
Lift a function to actions.
Equivalent to Functor's fmap
but implemented using only Applicative
's methods:
`liftA f a = pure f * a`
As such this function may be used to implement a Functor
instance from an Applicative
one.
flip :: (a -> b -> c) -> b -> a -> c #
takes its (first) two arguments in the reverse order of flip
ff
.
>>>
flip (++) "hello" "world"
"worldhello"
const x
is a unary function which evaluates to x
for all inputs.
>>>
const 42 "hello"
42
>>>
map (const 42) [0..3]
[42,42,42,42]
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=
, but with the arguments interchanged.
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*>
with the arguments reversed.
chunksOf :: Int -> [a] -> [[a]] Source #
Given a maximum length, splits a list into sublists
>>>
chunksOf 5 (take 30 $ repeat 'a')
["aaaaa","aaaaa","aaaaa","aaaaa","aaaaa","aaaaa"]
(.:) :: (a -> b) -> (c -> d -> a) -> c -> d -> b Source #
Multivariable composition.
f .: g ≡ (f .) . g ≡ \c d -> f (g c d)
Non-empty (and non-strict) list type.
Since: base-4.9.0.0
a :| [a] infixr 5 |
Instances
MonadFix NonEmpty | Since: base-4.9.0.0 |
Defined in Control.Monad.Fix | |
Foldable NonEmpty | Since: base-4.9.0.0 |
Defined in Data.Foldable 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 # | |
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 |
Traversable NonEmpty | Since: base-4.9.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 |
NFData1 NonEmpty | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Generic1 NonEmpty | |
Lift a => Lift (NonEmpty a :: Type) | Since: template-haskell-2.15.0.0 |
Semigroup (NonEmpty a) | Since: base-4.9.0.0 |
IsList (NonEmpty a) | Since: base-4.9.0.0 |
Generic (NonEmpty a) | |
Read a => Read (NonEmpty a) | Since: base-4.11.0.0 |
Show a => Show (NonEmpty a) | Since: base-4.11.0.0 |
NFData a => NFData (NonEmpty a) | Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
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.Generics type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 []))) | |
type Item (NonEmpty a) | |
type Rep (NonEmpty a) | Since: base-4.6.0.0 |
Defined in GHC.Generics type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Base" "base" 'False) (C1 ('MetaCons ":|" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]))) |
notEmpty :: HasCallStack => [a] -> NonEmpty a Source #
fromList
with a better error message. Useful to
silence GHC's Pattern match(es) are non-exhaustive warning in places where
the programmer knows it's always non-empty, but it's infeasible to express
that in the type system.
safeGetWindowAttributes :: Window -> X (Maybe WindowAttributes) Source #
A safe version of getWindowAttributes
.
mkAbsolutePath :: MonadIO m => FilePath -> m FilePath Source #
(Naïvely) turn a relative path into an absolute one.
- If the path starts with
/
, do nothing. - If it starts with
~/
, replace that with the actual home - directory.
- If it starts with
$
, read the name of an environment - variable and replace it with the contents of that.
- Otherwise, prepend the home directory and
/
to the path.
findM :: Monad m => (a -> m Bool) -> [a] -> m (Maybe a) Source #
Like find
, but takes a monadic function instead; retains the
short-circuiting behaviour of the non-monadic version.
For example,
findM (\a -> putStr (show a <> " ") >> pure False) [1..10]
would print "1 2 3 4 5 6 7 8 9 10" and return Nothing
, while
findM (\a -> putStr (show a <> " ") >> pure True) [1..10]
would print "1"
and return Just 1
.
Keys
Convert a modifier mask into a useful string.
cleanKeyMask :: X (KeyMask -> KeyMask) Source #
Strip numlock, capslock, mouse buttons and XKB group from a KeyMask
,
leaving only modifier keys like Shift, Control, Super, Hyper in the mask
(hence the "Key" in "cleanKeyMask").
Core's cleanMask
only strips the first two because key events from
passive grabs (key bindings) are stripped of mouse buttons and XKB group by
the X server already for compatibility reasons. For more info, see:
https://www.x.org/releases/X11R7.7/doc/kbproto/xkbproto.html#Delivering_a_Key_or_Button_Event_to_a_Client
regularKeys :: [(String, KeySym)] Source #
A list of "regular" (extended ASCII) keys.
allSpecialKeys :: [(String, KeySym)] Source #
A list of all special key names and their associated KeySyms.
specialKeys :: [(String, KeySym)] Source #
A list of special key names and their corresponding KeySyms.
multimediaKeys :: [(String, KeySym)] Source #
List of multimedia keys. If Xlib does not know about some keysym
it's omitted from the list (stringToKeysym
returns noSymbol
in
this case).
functionKeys :: [(String, KeySym)] Source #
A list pairing function key descriptor strings (e.g. "<F2>"
)
with the associated KeySyms.
Infinite streams
An infinite stream type
takeS :: Int -> Stream a -> [a] Source #
takeS n stream
returns the first n
elements of stream
; if n < 0
,
this returns the empty list.