Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data Text
- data ByteString
- data Word8
- fmt :: QuasiQuoter
- textToString :: Text -> String
- stringToText :: String -> Text
- showToText :: Show a => a -> Text
- textToBytesUtf8 :: Text -> ByteString
- textToBytesUtf8Lazy :: Text -> ByteString
- bytesToTextUtf8 :: ByteString -> Either Error Text
- bytesToTextUtf8Lazy :: ByteString -> Either Error Text
- bytesToTextUtf8Lenient :: ByteString -> Text
- bytesToTextUtf8LenientLazy :: ByteString -> Text
- bytesToTextUtf8Unsafe :: ByteString -> Text
- bytesToTextUtf8UnsafeLazy :: ByteString -> Text
- toStrict :: Text -> Text
- toLazy :: Text -> Text
- toStrictBytes :: ByteString -> ByteString
- toLazyBytes :: ByteString -> ByteString
- charToWordUnsafe :: Char -> Word8
- putStrLn :: String -> IO ()
- putStderrLn :: Text -> IO ()
- exitWithMessage :: Text -> IO a
- todo :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => a
- class HasField (x :: k) r a | x r -> a
- doAs :: forall m a. m a -> m a
- (&) :: a -> (a -> b) -> b
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- (<|>) :: Alternative f => f a -> f a -> f a
- foldMap1 :: (Foldable1 t, Semigroup m) => (a -> m) -> t a -> m
- foldMap' :: (Foldable t, Monoid m) => (a -> m) -> t a -> m
- join :: Monad m => m (m a) -> m a
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- guard :: Alternative f => Bool -> f ()
- newtype ExceptT e (m :: Type -> Type) a = ExceptT (m (Either e a))
- runExceptT :: ExceptT e m a -> m (Either e a)
- class Monad m => MonadThrow (m :: Type -> Type)
- throwM :: (MonadThrow m, Exception e) => e -> m a
- class Monad m => MonadIO (m :: Type -> Type)
- liftIO :: MonadIO m => IO a -> m a
- class Monad m => MonadReader r (m :: Type -> Type) | m -> r
- asks :: MonadReader r m => (r -> a) -> m a
- class Bifunctor (p :: Type -> Type -> Type)
- first :: Bifunctor p => (a -> b) -> p a c -> p b c
- second :: Bifunctor p => (b -> c) -> p a b -> p a c
- bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d
- both :: Bifunctor bi => (a -> b) -> bi a a -> bi b b
- foldMap :: (Foldable t, Monoid m) => (a -> m) -> t a -> m
- fold :: (Foldable t, Monoid m) => t m -> m
- foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b
- fromMaybe :: a -> Maybe a -> a
- mapMaybe :: (a -> Maybe b) -> [a] -> [b]
- findMaybe :: Foldable t => (a -> Maybe b) -> t a -> Maybe b
- class (Functor t, Foldable t) => Traversable (t :: Type -> Type)
- for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)
- for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
- traverse :: (Traversable t, Applicative f) => (a -> f b) -> t a -> f (t b)
- traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
- traverseFold :: (Applicative ap, Traversable t, Monoid m) => (a -> ap m) -> t a -> ap m
- traverseFold1 :: (Applicative ap, Traversable1 t, Semigroup s) => (a -> ap s) -> t a -> ap s
- traverseFoldDefault :: (Applicative ap, Traversable t, Semigroup m) => m -> (a -> ap m) -> t a -> ap m
- class MonadTrans (t :: (Type -> Type) -> Type -> Type)
- lift :: (MonadTrans t, Monad m) => m a -> t m a
- class a ~R# b => Coercible (a :: k) (b :: k)
- coerce :: forall {k :: RuntimeRep} (a :: TYPE k) (b :: TYPE k). Coercible a b => a -> b
- data Proxy (t :: k) = Proxy
- data Map k a
- annotate :: err -> Maybe a -> Either err a
- data Validation e a
- failure :: e -> Validation (NonEmpty e) a
- successes :: [Validation e a] -> [a]
- failures :: [Validation e a] -> [e]
- traverseValidate :: forall t a err b. Traversable t => (a -> Either err b) -> t a -> Either (NonEmpty err) (t b)
- traverseValidateM :: forall t m a err b. (Traversable t, Applicative m) => (a -> m (Either err b)) -> t a -> m (Either (NonEmpty err) (t b))
- traverseValidateM_ :: forall t m a err. (Traversable t, Applicative m) => (a -> m (Either err ())) -> t a -> m (Either (NonEmpty err) ())
- eitherToValidation :: Either e a -> Validation e a
- eitherToListValidation :: Either a c -> Validation (NonEmpty a) c
- validationToEither :: Validation e a -> Either e a
- data These a b
- eitherToThese :: Either err a -> These err a
- eitherToListThese :: Either err a -> These (NonEmpty err) a
- validationToThese :: Validation err a -> These err a
- thenThese :: (Monad m, Semigroup err) => (a -> m (These err b)) -> m (These err a) -> m (These err b)
- thenValidate :: (a -> Validation err b) -> Validation err a -> Validation err b
- thenValidateM :: Monad m => (a -> m (Validation err b)) -> m (Validation err a) -> m (Validation err b)
- data NonEmpty a = a :| [a]
- singleton :: a -> NonEmpty a
- nonEmpty :: [a] -> Maybe (NonEmpty a)
- nonEmptyDef :: a -> [a] -> NonEmpty a
- toList :: Foldable t => t a -> [a]
- toNonEmptyDefault :: a -> [a] -> NonEmpty a
- maximum1 :: (Foldable1 f, Ord a) => f a -> a
- minimum1 :: (Foldable1 f, Ord a) => f a -> a
- data Vector a
- class Generic a
- class Lift (t :: TYPE r)
- class Semigroup a
- sconcat :: Semigroup a => NonEmpty a -> a
- class Semigroup a => Monoid a
- mconcat :: Monoid a => [a] -> a
- ifTrue :: Monoid m => Bool -> m -> m
- ifExists :: Monoid m => Maybe m -> m
- data Void
- absurd :: Void -> a
- newtype Identity a = Identity {
- runIdentity :: a
- data Natural
- intToNatural :: Integral a => a -> Maybe Natural
- data Scientific
- class Contravariant (f :: Type -> Type)
- contramap :: Contravariant f => (a' -> a) -> f a -> f a'
- (>$<) :: Contravariant f => (a -> b) -> f b -> f a
- (>&<) :: Contravariant f => f b -> (a -> b) -> f a
- class Profunctor (p :: Type -> Type -> Type)
- dimap :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d
- lmap :: Profunctor p => (a -> b) -> p b c -> p a c
- rmap :: Profunctor p => (b -> c) -> p a b -> p a c
- class Semigroupoid (c :: k -> k -> Type)
- class Category (cat :: k -> k -> Type)
- (>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c
- (&>>) :: Semigroupoid s => s a b -> s b c -> s a c
- type family Any :: k where ...
- inverseFunction :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> k -> Maybe a
- inverseMap :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> Map k a
- enumerateAll :: (Enum a, Bounded a) => [a]
- mapFromListOn :: Ord key => (a -> key) -> [a] -> Map key a
- mapFromListOnMerge :: (Ord key, Semigroup s) => (a -> (key, s)) -> [a] -> Map key s
- type HasCallStack = ?callStack :: CallStack
- module Data.Error
Text conversions
A space efficient, packed, unboxed Unicode text type.
Instances
PyFToString Text | |
Defined in PyF.Class pyfToString :: Text -> String # | |
Hashable Text | |
Defined in Data.Hashable.Class | |
type PyFClassify Text | |
Defined in PyF.Class | |
type Item Text | |
data ByteString #
A space-efficient representation of a Word8
vector, supporting many
efficient operations.
A ByteString
contains 8-bit bytes, or by using the operations from
Data.ByteString.Char8 it can be interpreted as containing 8-bit
characters.
Instances
8-bit unsigned integer type
Instances
Data Word8 | Since: base-4.0.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word8 -> c Word8 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word8 # dataTypeOf :: Word8 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word8) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word8) # gmapT :: (forall b. Data b => b -> b) -> Word8 -> Word8 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word8 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word8 -> r # gmapQ :: (forall d. Data d => d -> u) -> Word8 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word8 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # | |
Bits Word8 | Since: base-2.1 |
Defined in GHC.Word (.&.) :: Word8 -> Word8 -> Word8 # (.|.) :: Word8 -> Word8 -> Word8 # xor :: Word8 -> Word8 -> Word8 # complement :: Word8 -> Word8 # shift :: Word8 -> Int -> Word8 # rotate :: Word8 -> Int -> Word8 # setBit :: Word8 -> Int -> Word8 # clearBit :: Word8 -> Int -> Word8 # complementBit :: Word8 -> Int -> Word8 # testBit :: Word8 -> Int -> Bool # bitSizeMaybe :: Word8 -> Maybe Int # shiftL :: Word8 -> Int -> Word8 # unsafeShiftL :: Word8 -> Int -> Word8 # shiftR :: Word8 -> Int -> Word8 # unsafeShiftR :: Word8 -> Int -> Word8 # rotateL :: Word8 -> Int -> Word8 # | |
FiniteBits Word8 | Since: base-4.6.0.0 |
Defined in GHC.Word finiteBitSize :: Word8 -> Int # countLeadingZeros :: Word8 -> Int # countTrailingZeros :: Word8 -> Int # | |
Bounded Word8 | Since: base-2.1 |
Enum Word8 | Since: base-2.1 |
Ix Word8 | Since: base-2.1 |
Num Word8 | Since: base-2.1 |
Read Word8 | Since: base-2.1 |
Integral Word8 | Since: base-2.1 |
Real Word8 | Since: base-2.1 |
Defined in GHC.Word toRational :: Word8 -> Rational # | |
Show Word8 | Since: base-2.1 |
Eq Word8 | Since: base-2.1 |
Ord Word8 | Since: base-2.1 |
Hashable Word8 | |
Defined in Data.Hashable.Class | |
IArray UArray Word8 | |
Defined in Data.Array.Base bounds :: Ix i => UArray i Word8 -> (i, i) # numElements :: Ix i => UArray i Word8 -> Int unsafeArray :: Ix i => (i, i) -> [(Int, Word8)] -> UArray i Word8 unsafeAt :: Ix i => UArray i Word8 -> Int -> Word8 unsafeReplace :: Ix i => UArray i Word8 -> [(Int, Word8)] -> UArray i Word8 unsafeAccum :: Ix i => (Word8 -> e' -> Word8) -> UArray i Word8 -> [(Int, e')] -> UArray i Word8 unsafeAccumArray :: Ix i => (Word8 -> e' -> Word8) -> Word8 -> (i, i) -> [(Int, e')] -> UArray i Word8 | |
Lift Word8 | |
MArray (STUArray s) Word8 (ST s) | |
Defined in Data.Array.Base getBounds :: Ix i => STUArray s i Word8 -> ST s (i, i) # getNumElements :: Ix i => STUArray s i Word8 -> ST s Int newArray :: Ix i => (i, i) -> Word8 -> ST s (STUArray s i Word8) # newArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word8) # unsafeNewArray_ :: Ix i => (i, i) -> ST s (STUArray s i Word8) unsafeRead :: Ix i => STUArray s i Word8 -> Int -> ST s Word8 unsafeWrite :: Ix i => STUArray s i Word8 -> Int -> Word8 -> ST s () | |
type PyFClassify Word8 | |
Defined in PyF.Class |
fmt :: QuasiQuoter #
Generic formatter, can format an expression to any t
as long as
t
is an instance of IsString
.
textToString :: Text -> String Source #
stringToText :: String -> Text Source #
showToText :: Show a => a -> Text Source #
textToBytesUtf8 :: Text -> ByteString Source #
encode a Text to a UTF-8 encoded Bytestring
textToBytesUtf8Lazy :: Text -> ByteString Source #
encode a lazy Text to a UTF-8 encoded lazy Bytestring
bytesToTextUtf8 :: ByteString -> Either Error Text Source #
bytesToTextUtf8Lenient :: ByteString -> Text Source #
decode a Text from a ByteString that is assumed to be UTF-8, replace non-UTF-8 characters with the replacment char U+FFFD.
bytesToTextUtf8LenientLazy :: ByteString -> Text Source #
decode a lazy Text from a lazy ByteString that is assumed to be UTF-8, replace non-UTF-8 characters with the replacment char U+FFFD.
bytesToTextUtf8Unsafe :: ByteString -> Text Source #
decode a Text from a ByteString that is assumed to be UTF-8 (crash if that is not the case)
bytesToTextUtf8UnsafeLazy :: ByteString -> Text Source #
decode a Text from a ByteString that is assumed to be UTF-8 (crash if that is not the case)
toStrictBytes :: ByteString -> ByteString Source #
toLazyBytes :: ByteString -> ByteString Source #
charToWordUnsafe :: Char -> Word8 Source #
IO
putStderrLn :: Text -> IO () Source #
Put the text to stderr
.
exitWithMessage :: Text -> IO a Source #
WIP code
todo :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => a Source #
Warning: todo
(undefined code) remains in code
Use this in places where the code is still to be implemented.
It always type-checks and will show a warning at compile time if it was forgotten in the code.
Use instead of error
and undefined
for code that hasn’t been written.
Uses the same trick as https://hackage.haskell.org/package/protolude-0.3.0/docs/src/Protolude.Error.html#error
Records
class HasField (x :: k) r a | x r -> a #
Constraint representing the fact that the field x
belongs to
the record type r
and has field type a
. This will be solved
automatically, but manual instances may be provided as well.
Control flow
doAs :: forall m a. m a -> m a Source #
Mark a `do`-block with the type of the Monad/Applicativ it uses. Only intended for reading ease and making code easier to understand, especially do-blocks that use unconventional monads (like Maybe or List).
Example:
doAs @Maybe $ do a <- Justa
b <- Justb
pure (a, b)
(<|>) :: Alternative f => f a -> f a -> f a infixl 3 #
An associative binary operation
foldMap1 :: (Foldable1 t, Semigroup m) => (a -> m) -> t a -> m #
Map each element of the structure to a semigroup, and combine the results.
>>>
foldMap1 Sum (1 :| [2, 3, 4])
Sum {getSum = 10}
foldMap' :: (Foldable t, 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
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
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.
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
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)
newtype ExceptT e (m :: Type -> Type) a #
A monad transformer that adds exceptions to other monads.
ExceptT
constructs a monad parameterized over two things:
- e - The exception type.
- m - The inner monad.
The return
function yields a computation that produces the given
value, while >>=
sequences two subcomputations, exiting on the
first exception.
Instances
runExceptT :: ExceptT e m a -> m (Either e a) #
The inverse of ExceptT
.
class Monad m => MonadThrow (m :: Type -> Type) #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
Instances
throwM :: (MonadThrow m, Exception e) => e -> m a #
Throw an exception. Note that this throws when this action is run in
the monad m
, not when it is applied. It is a generalization of
Control.Exception's throwIO
.
Should satisfy the law:
throwM e >> f = throwM e
class Monad m => MonadIO (m :: Type -> Type) #
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Instances
MonadIO IO | Since: base-4.9.0.0 |
Defined in Control.Monad.IO.Class | |
MonadIO Q | |
Defined in Language.Haskell.TH.Syntax | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
MonadIO m => MonadIO (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
MonadIO m => MonadIO (IdentityT m) | |
Defined in Control.Monad.Trans.Identity |
liftIO :: MonadIO m => IO a -> m a #
Lift a computation from the IO
monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO
is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted
, we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO ()
and
.IO
()
Luckily, we know of a function that takes an
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3
class Monad m => MonadReader r (m :: Type -> Type) | m -> r #
See examples in Control.Monad.Reader.
Note, the partially applied function type (->) r
is a simple reader monad.
See the instance
declaration below.
Instances
MonadReader r m => MonadReader r (ListT m) | |
MonadReader r m => MonadReader r (MaybeT m) | |
(Error e, MonadReader r m) => MonadReader r (ErrorT e m) | |
MonadReader r m => MonadReader r (ExceptT e m) | Since: mtl-2.2 |
MonadReader r m => MonadReader r (IdentityT m) | |
Monad m => MonadReader r (ReaderT r m) | |
MonadReader r m => MonadReader r (StateT s m) | |
MonadReader r m => MonadReader r (StateT s m) | |
(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
(Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
MonadReader r ((->) r) | |
MonadReader r' m => MonadReader r' (ContT r m) | |
(Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
(Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
:: MonadReader r m | |
=> (r -> a) | The selector function to apply to the environment. |
-> m a |
Retrieves a function of the current environment.
class Bifunctor (p :: Type -> Type -> Type) #
A bifunctor is a type constructor that takes
two type arguments and is a functor in both arguments. That
is, unlike with Functor
, a type constructor such as Either
does not need to be partially applied for a Bifunctor
instance, and the methods in this class permit mapping
functions over the Left
value or the Right
value,
or both at the same time.
Formally, the class Bifunctor
represents a bifunctor
from Hask
-> Hask
.
Intuitively it is a bifunctor where both the first and second arguments are covariant.
You can define a Bifunctor
by either defining bimap
or by
defining both first
and second
.
If you supply bimap
, you should ensure that:
bimap
id
id
≡id
If you supply first
and second
, ensure:
first
id
≡id
second
id
≡id
If you supply both, you should also ensure:
bimap
f g ≡first
f.
second
g
These ensure by parametricity:
bimap
(f.
g) (h.
i) ≡bimap
f h.
bimap
g ifirst
(f.
g) ≡first
f.
first
gsecond
(f.
g) ≡second
f.
second
g
Since: base-4.8.0.0
Instances
Bifunctor Either | Since: base-4.8.0.0 |
Bifunctor Arg | Since: base-4.9.0.0 |
Bifunctor These | |
Bifunctor Validation | Similar to Examples
|
Defined in Validation bimap :: (a -> b) -> (c -> d) -> Validation a c -> Validation b d # first :: (a -> b) -> Validation a c -> Validation b c # second :: (b -> c) -> Validation a b -> Validation a c # | |
Bifunctor (,) | Since: base-4.8.0.0 |
Bifunctor (Const :: Type -> Type -> Type) | Since: base-4.8.0.0 |
Bifunctor (Tagged :: Type -> Type -> Type) | |
Bifunctor ((,,) x1) | Since: base-4.8.0.0 |
Bifunctor (K1 i :: Type -> Type -> Type) | Since: base-4.9.0.0 |
Bifunctor ((,,,) x1 x2) | Since: base-4.8.0.0 |
Functor f => Bifunctor (Clown f :: Type -> Type -> Type) | |
Bifunctor p => Bifunctor (Flip p) | |
Functor g => Bifunctor (Joker g :: Type -> Type -> Type) | |
Bifunctor p => Bifunctor (WrappedBifunctor p) | |
Defined in Data.Bifunctor.Wrapped bimap :: (a -> b) -> (c -> d) -> WrappedBifunctor p a c -> WrappedBifunctor p b d # first :: (a -> b) -> WrappedBifunctor p a c -> WrappedBifunctor p b c # second :: (b -> c) -> WrappedBifunctor p a b -> WrappedBifunctor p a c # | |
Bifunctor ((,,,,) x1 x2 x3) | Since: base-4.8.0.0 |
(Bifunctor f, Bifunctor g) => Bifunctor (Product f g) | |
(Bifunctor p, Bifunctor q) => Bifunctor (Sum p q) | |
Bifunctor ((,,,,,) x1 x2 x3 x4) | Since: base-4.8.0.0 |
(Functor f, Bifunctor p) => Bifunctor (Tannen f p) | |
Bifunctor ((,,,,,,) x1 x2 x3 x4 x5) | Since: base-4.8.0.0 |
(Bifunctor p, Functor f, Functor g) => Bifunctor (Biff p f g) | |
both :: Bifunctor bi => (a -> b) -> bi a a -> bi b b Source #
Map the same function over both sides of a Bifunctor (e.g. a tuple).
foldMap :: (Foldable t, 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"
fold :: (Foldable t, 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
foldl' :: Foldable t => (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
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
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]
findMaybe :: Foldable t => (a -> Maybe b) -> t a -> Maybe b Source #
Find the first element for which pred returns `Just a`, and return the a
.
Example: @ >>> :set -XTypeApplications >>> import qualified Text.Read
>>>
findMaybe (Text.Read.readMaybe @Int) ["foo"]
Nothing>>>
findMaybe (Text.Read.readMaybe @Int) ["foo", "34.40", "34", "abc"]
Just 34
class (Functor t, Foldable t) => Traversable (t :: Type -> Type) #
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.
Instances
Traversable ZipList | Since: base-4.9.0.0 |
Traversable Complex | Since: base-4.9.0.0 |
Traversable Identity | Since: base-4.9.0.0 |
Traversable First | Since: base-4.8.0.0 |
Traversable Last | Since: base-4.8.0.0 |
Traversable Down | Since: base-4.12.0.0 |
Traversable First | Since: base-4.9.0.0 |
Traversable Last | Since: base-4.9.0.0 |
Traversable Max | Since: base-4.9.0.0 |
Traversable Min | Since: base-4.9.0.0 |
Traversable Dual | Since: base-4.8.0.0 |
Traversable Product | Since: base-4.8.0.0 |
Traversable Sum | Since: base-4.8.0.0 |
Traversable Par1 | Since: base-4.9.0.0 |
Traversable SCC | Since: containers-0.5.9 |
Traversable IntMap | Traverses in order of increasing key. |
Traversable Digit | |
Traversable Elem | |
Traversable FingerTree | |
Defined in Data.Sequence.Internal traverse :: Applicative f => (a -> f b) -> FingerTree a -> f (FingerTree b) # sequenceA :: Applicative f => FingerTree (f a) -> f (FingerTree a) # mapM :: Monad m => (a -> m b) -> FingerTree a -> m (FingerTree b) # sequence :: Monad m => FingerTree (m a) -> m (FingerTree a) # | |
Traversable Node | |
Traversable Seq | |
Traversable ViewL | |
Traversable ViewR | |
Traversable Tree | |
Traversable UniqueMap | |
Defined in GHC.Cmm.Dataflow.Collections | |
Traversable LabelMap | |
Traversable Bag | |
Traversable SizedSeq | |
Traversable GenClosure | |
Defined in GHC.Exts.Heap.Closures traverse :: Applicative f => (a -> f b) -> GenClosure a -> f (GenClosure b) # sequenceA :: Applicative f => GenClosure (f a) -> f (GenClosure a) # mapM :: Monad m => (a -> m b) -> GenClosure a -> m (GenClosure b) # sequence :: Monad m => GenClosure (m a) -> m (GenClosure a) # | |
Traversable Array | |
Traversable Vector | |
Traversable NonEmpty | Since: base-4.9.0.0 |
Traversable Maybe | Since: base-2.1 |
Traversable Solo | Since: base-4.15 |
Traversable [] | Since: base-2.1 |
Defined in Data.Traversable | |
Traversable (Either a) | Since: base-4.7.0.0 |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Traversable (Arg a) | Since: base-4.9.0.0 |
Ix i => Traversable (Array i) | Since: base-2.1 |
Traversable (U1 :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (UAddr :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (UChar :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (UDouble :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (UFloat :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (UInt :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (UWord :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (V1 :: Type -> Type) | Since: base-4.9.0.0 |
Traversable (Map k) | Traverses in order of increasing key. |
Traversable (These a) | |
Traversable f => Traversable (Lift f) | |
Traversable (HashMap k) | |
Traversable (Validation e) | Traverse values inside Examples
|
Defined in Validation traverse :: Applicative f => (a -> f b) -> Validation e a -> f (Validation e b) # sequenceA :: Applicative f => Validation e (f a) -> f (Validation e a) # mapM :: Monad m => (a -> m b) -> Validation e a -> m (Validation e b) # sequence :: Monad m => Validation e (m a) -> m (Validation e a) # | |
Traversable ((,) a) | Since: base-4.7.0.0 |
Defined in Data.Traversable | |
Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Traversable f => Traversable (Ap f) | Since: base-4.12.0.0 |
Traversable f => Traversable (Alt f) | Since: base-4.12.0.0 |
Traversable f => Traversable (Rec1 f) | Since: base-4.9.0.0 |
Bitraversable p => Traversable (Join p) | |
Traversable (Tagged s) | |
Traversable f => Traversable (Backwards f) | Derived instance. |
Defined in Control.Applicative.Backwards | |
Traversable f => Traversable (ErrorT e f) | |
Defined in Control.Monad.Trans.Error | |
Traversable f => Traversable (ExceptT e f) | |
Defined in Control.Monad.Trans.Except | |
Traversable f => Traversable (IdentityT f) | |
Defined in Control.Monad.Trans.Identity | |
Traversable f => Traversable (Reverse f) | Traverse from right to left. |
Defined in Data.Functor.Reverse | |
(Traversable f, Traversable g) => Traversable (Product f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Product | |
(Traversable f, Traversable g) => Traversable (Sum f g) | Since: base-4.9.0.0 |
(Traversable f, Traversable g) => Traversable (f :*: g) | Since: base-4.9.0.0 |
(Traversable f, Traversable g) => Traversable (f :+: g) | Since: base-4.9.0.0 |
Traversable (K1 i c :: Type -> Type) | Since: base-4.9.0.0 |
(Traversable f, Traversable g) => Traversable (Compose f g) | Since: base-4.9.0.0 |
Defined in Data.Functor.Compose | |
(Traversable f, Traversable g) => Traversable (f :.: g) | Since: base-4.9.0.0 |
Traversable f => Traversable (M1 i c f) | Since: base-4.9.0.0 |
Traversable (Clown f a :: Type -> Type) | |
Defined in Data.Bifunctor.Clown | |
Bitraversable p => Traversable (Flip p a) | |
Traversable g => Traversable (Joker g a) | |
Defined in Data.Bifunctor.Joker | |
Bitraversable p => Traversable (WrappedBifunctor p a) | |
Defined in Data.Bifunctor.Wrapped traverse :: Applicative f => (a0 -> f b) -> WrappedBifunctor p a a0 -> f (WrappedBifunctor p a b) # sequenceA :: Applicative f => WrappedBifunctor p a (f a0) -> f (WrappedBifunctor p a a0) # mapM :: Monad m => (a0 -> m b) -> WrappedBifunctor p a a0 -> m (WrappedBifunctor p a b) # sequence :: Monad m => WrappedBifunctor p a (m a0) -> m (WrappedBifunctor p a a0) # | |
(Traversable (f a), Traversable (g a)) => Traversable (Product f g a) | |
Defined in Data.Bifunctor.Product traverse :: Applicative f0 => (a0 -> f0 b) -> Product f g a a0 -> f0 (Product f g a b) # sequenceA :: Applicative f0 => Product f g a (f0 a0) -> f0 (Product f g a a0) # mapM :: Monad m => (a0 -> m b) -> Product f g a a0 -> m (Product f g a b) # sequence :: Monad m => Product f g a (m a0) -> m (Product f g a a0) # | |
(Traversable (f a), Traversable (g a)) => Traversable (Sum f g a) | |
Defined in Data.Bifunctor.Sum | |
(Traversable f, Bitraversable p) => Traversable (Tannen f p a) | |
Defined in Data.Bifunctor.Tannen traverse :: Applicative f0 => (a0 -> f0 b) -> Tannen f p a a0 -> f0 (Tannen f p a b) # sequenceA :: Applicative f0 => Tannen f p a (f0 a0) -> f0 (Tannen f p a a0) # mapM :: Monad m => (a0 -> m b) -> Tannen f p a a0 -> m (Tannen f p a b) # sequence :: Monad m => Tannen f p a (m a0) -> m (Tannen f p a a0) # | |
(Bitraversable p, Traversable g) => Traversable (Biff p f g a) | |
Defined in Data.Bifunctor.Biff traverse :: Applicative f0 => (a0 -> f0 b) -> Biff p f g a a0 -> f0 (Biff p f g a b) # sequenceA :: Applicative f0 => Biff p f g a (f0 a0) -> f0 (Biff p f g a a0) # mapM :: Monad m => (a0 -> m b) -> Biff p f g a a0 -> m (Biff p f g a b) # sequence :: Monad m => Biff p f g a (m a0) -> m (Biff p f g a a0) # |
for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) #
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
traverse :: (Traversable t, 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
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" "!"
traverseFold :: (Applicative ap, Traversable t, Monoid m) => (a -> ap m) -> t a -> ap m Source #
Run some function producing applicative over a traversable data structure, then collect the results in a Monoid.
Very helpful with side-effecting functions returning (Validation err a)
:
let f :: Text -> IO (Validation (NonEmpty Error) Text) f t = pure $ if t == "foo" then Success t else Failure (singleton ("not foo: " <> t)) in traverseFold f [ "foo", "bar", "baz" ] == Failure ("not foo bar" :| ["not foo baz"])
… since (Semigroup err => Validation err a)
is a Semigroup
/Monoid
itself.
traverseFold1 :: (Applicative ap, Traversable1 t, Semigroup s) => (a -> ap s) -> t a -> ap s Source #
Same as traverseFold
, but with a Semigroup
and Traversable1
restriction.
traverseFoldDefault :: (Applicative ap, Traversable t, Semigroup m) => m -> (a -> ap m) -> t a -> ap m Source #
Like traverseFold
, but fold over a semigroup instead of a Monoid, by providing a starting element.
class MonadTrans (t :: (Type -> Type) -> Type -> Type) #
The class of monad transformers. Instances should satisfy the
following laws, which state that lift
is a monad transformation:
Instances
MonadTrans (ErrorT e) | |
Defined in Control.Monad.Trans.Error | |
MonadTrans (ExceptT e) | |
Defined in Control.Monad.Trans.Except | |
MonadTrans (IdentityT :: (Type -> Type) -> Type -> Type) | |
Defined in Control.Monad.Trans.Identity |
lift :: (MonadTrans t, Monad m) => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
Data types
class a ~R# b => Coercible (a :: k) (b :: k) #
Coercible
is a two-parameter class that has instances for types a
and b
if
the compiler can infer that they have the same representation. This class
does not have regular instances; instead they are created on-the-fly during
type-checking. Trying to manually declare an instance of Coercible
is an error.
Nevertheless one can pretend that the following three kinds of instances exist. First, as a trivial base-case:
instance Coercible a a
Furthermore, for every type constructor there is
an instance that allows to coerce under the type constructor. For
example, let D
be a prototypical type constructor (data
or
newtype
) with three type arguments, which have roles nominal
,
representational
resp. phantom
. Then there is an instance of
the form
instance Coercible b b' => Coercible (D a b c) (D a b' c')
Note that the nominal
type arguments are equal, the
representational
type arguments can differ, but need to have a
Coercible
instance themself, and the phantom
type arguments can be
changed arbitrarily.
The third kind of instance exists for every newtype NT = MkNT T
and
comes in two variants, namely
instance Coercible a T => Coercible a NT
instance Coercible T b => Coercible NT b
This instance is only usable if the constructor MkNT
is in scope.
If, as a library author of a type constructor like Set a
, you
want to prevent a user of your module to write
coerce :: Set T -> Set NT
,
you need to set the role of Set
's type parameter to nominal
,
by writing
type role Set nominal
For more details about this feature, please refer to Safe Coercions by Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones and Stephanie Weirich.
Since: ghc-prim-4.7.0.0
coerce :: forall {k :: RuntimeRep} (a :: TYPE k) (b :: TYPE k). Coercible a b => a -> b #
The function coerce
allows you to safely convert between values of
types that have the same representation with no run-time overhead. In the
simplest case you can use it instead of a newtype constructor, to go from
the newtype's concrete type to the abstract type. But it also works in
more complicated settings, e.g. converting a list of newtypes to a list of
concrete types.
This function is runtime-representation polymorphic, but the
RuntimeRep
type argument is marked as Inferred
, meaning
that it is not available for visible type application. This means
the typechecker will accept coerce @Int @Age 42
.
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a
idiom.undefined
:: a
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
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 # | |
Eq1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Ord1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: TYPE LiftedRep -> Type) | Since: base-4.9.0.0 |
Contravariant (Proxy :: Type -> Type) | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Alt (Proxy :: Type -> Type) | |
Apply (Proxy :: Type -> Type) | |
Bind (Proxy :: Type -> Type) | |
Extend (Proxy :: Type -> Type) | |
Data t => Data (Proxy t) | Since: base-4.7.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Proxy t -> c (Proxy t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Proxy t) # toConstr :: Proxy t -> Constr # dataTypeOf :: Proxy t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Proxy t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Proxy t)) # gmapT :: (forall b. Data b => b -> b) -> Proxy t -> Proxy t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Proxy t -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Proxy t -> r # gmapQ :: (forall d. Data d => d -> u) -> Proxy t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Proxy t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # | |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Ix (Proxy s) | Since: base-4.7.0.0 |
Defined in Data.Proxy | |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |
A Map from keys k
to values a
.
The Semigroup
operation for Map
is union
, which prefers
values from the left operand. If m1
maps a key k
to a value
a1
, and m2
maps the same key to a different value a2
, then
their union m1 <> m2
maps k
to a1
.
Instances
Bifoldable Map | Since: containers-0.6.3.1 |
Eq2 Map | Since: containers-0.5.9 |
Ord2 Map | Since: containers-0.5.9 |
Defined in Data.Map.Internal | |
Show2 Map | Since: containers-0.5.9 |
Hashable2 Map | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
(OutputableP env key, OutputableP env elt) => OutputableP env (Map key elt) | |
Defined in GHC.Utils.Outputable | |
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 # | |
Eq k => Eq1 (Map k) | Since: containers-0.5.9 |
Ord k => Ord1 (Map k) | Since: containers-0.5.9 |
Defined in Data.Map.Internal | |
(Ord k, Read k) => Read1 (Map k) | Since: containers-0.5.9 |
Defined in Data.Map.Internal | |
Show k => Show1 (Map k) | Since: containers-0.5.9 |
Traversable (Map k) | Traverses in order of increasing key. |
Functor (Map k) | |
Ord k => TrieMap (Map k) | |
Defined in GHC.Data.TrieMap | |
Hashable k => Hashable1 (Map k) | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
Ord k => Alt (Map k) | |
Ord k => Apply (Map k) | A 'Map k' is not |
Ord k => Bind (Map k) | |
(Data k, Data a, Ord k) => Data (Map k a) | |
Defined in Data.Map.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Map k a -> c (Map k a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Map k a) # toConstr :: Map k a -> Constr # dataTypeOf :: Map k a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Map k a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k a)) # gmapT :: (forall b. Data b => b -> b) -> Map k a -> Map k a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Map k a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Map k a -> r # gmapQ :: (forall d. Data d => d -> u) -> Map k a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Map k a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) # | |
Ord k => Monoid (Map k v) | |
Ord k => Semigroup (Map k v) | |
Ord k => IsList (Map k v) | Since: containers-0.5.6.2 |
(Ord k, Read k, Read e) => Read (Map k e) | |
(Show k, Show a) => Show (Map k a) | |
(NFData k, NFData a) => NFData (Map k a) | |
Defined in Data.Map.Internal | |
(Outputable key, Outputable elt) => Outputable (Map key elt) | |
Defined in GHC.Utils.Outputable | |
(Eq k, Eq a) => Eq (Map k a) | |
(Ord k, Ord v) => Ord (Map k v) | |
(Hashable k, Hashable v) => Hashable (Map k v) | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
type Key (Map k) | |
Defined in GHC.Data.TrieMap | |
type Item (Map k v) | |
Defined in Data.Map.Internal |
data Validation e a #
Validation
is a polymorphic sum type for storing either all
validation failures or validation success. Unlike Either
, which
returns only the first error, Validation
accumulates all errors
using the Semigroup
typeclass.
Usually type variables in
are used as follows:Validation
e a
e
: is a list or set of failure messages or values of some error data type.a
: is some domain type denoting successful validation result.
Some typical use-cases:
Validation
[String
] User- Either list of
String
error messages or a validated value of a customUser
type.
- Either list of
Validation
(NonEmpty
UserValidationError) User- Similar to previous example, but list of failures guaranteed to be non-empty in case of validation failure, and it stores values of some custom error type.
Failure e | Validation failure. The |
Success a | Successful validation result of type |
Instances
Bifoldable Validation | Similar to Examples
|
Defined in Validation bifold :: Monoid m => Validation m m -> m # bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> Validation a b -> m # bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> Validation a b -> c # bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> Validation a b -> c # | |
Bifunctor Validation | Similar to Examples
|
Defined in Validation bimap :: (a -> b) -> (c -> d) -> Validation a c -> Validation b d # first :: (a -> b) -> Validation a c -> Validation b c # second :: (b -> c) -> Validation a b -> Validation a c # | |
Bitraversable Validation | Similar to Examples
|
Defined in Validation bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Validation a b -> f (Validation c d) # | |
NFData2 Validation | |
Defined in Validation liftRnf2 :: (a -> ()) -> (b -> ()) -> Validation a b -> () # | |
Generic1 (Validation e :: Type -> Type) | |
Defined in Validation type Rep1 (Validation e) :: k -> Type # from1 :: forall (a :: k). Validation e a -> Rep1 (Validation e) a # to1 :: forall (a :: k). Rep1 (Validation e) a -> Validation e a # | |
Foldable (Validation e) |
Examples
|
Defined in Validation fold :: Monoid m => Validation e m -> m # foldMap :: Monoid m => (a -> m) -> Validation e a -> m # foldMap' :: Monoid m => (a -> m) -> Validation e a -> m # foldr :: (a -> b -> b) -> b -> Validation e a -> b # foldr' :: (a -> b -> b) -> b -> Validation e a -> b # foldl :: (b -> a -> b) -> b -> Validation e a -> b # foldl' :: (b -> a -> b) -> b -> Validation e a -> b # foldr1 :: (a -> a -> a) -> Validation e a -> a # foldl1 :: (a -> a -> a) -> Validation e a -> a # toList :: Validation e a -> [a] # null :: Validation e a -> Bool # length :: Validation e a -> Int # elem :: Eq a => a -> Validation e a -> Bool # maximum :: Ord a => Validation e a -> a # minimum :: Ord a => Validation e a -> a # sum :: Num a => Validation e a -> a # product :: Num a => Validation e a -> a # | |
Traversable (Validation e) | Traverse values inside Examples
|
Defined in Validation traverse :: Applicative f => (a -> f b) -> Validation e a -> f (Validation e b) # sequenceA :: Applicative f => Validation e (f a) -> f (Validation e a) # mapM :: Monad m => (a -> m b) -> Validation e a -> m (Validation e b) # sequence :: Monad m => Validation e (m a) -> m (Validation e a) # | |
Monoid e => Alternative (Validation e) | This instance implements the behaviour when the first Examples
|
Defined in Validation empty :: Validation e a # (<|>) :: Validation e a -> Validation e a -> Validation e a # some :: Validation e a -> Validation e [a] # many :: Validation e a -> Validation e [a] # | |
Semigroup e => Applicative (Validation e) | This instance is the most important instance for the Examples
Implementations of all functions are lazy and they correctly work if some arguments are not fully evaluated.
|
Defined in Validation pure :: a -> Validation e a # (<*>) :: Validation e (a -> b) -> Validation e a -> Validation e b # liftA2 :: (a -> b -> c) -> Validation e a -> Validation e b -> Validation e c # (*>) :: Validation e a -> Validation e b -> Validation e b # (<*) :: Validation e a -> Validation e b -> Validation e a # | |
Functor (Validation e) | Allows changing the value inside Examples
|
Defined in Validation fmap :: (a -> b) -> Validation e a -> Validation e b # (<$) :: a -> Validation e b -> Validation e a # | |
(NoValidationMonadError, Semigroup e) => Monad (Validation e) | ⚠️CAUTION⚠️ This instance is for custom error display only. It's not possible to implement lawful In case it is used by mistake, the user will see the following:
|
Defined in Validation (>>=) :: Validation e a -> (a -> Validation e b) -> Validation e b # (>>) :: Validation e a -> Validation e b -> Validation e b # return :: a -> Validation e a # | |
NFData e => NFData1 (Validation e) | |
Defined in Validation liftRnf :: (a -> ()) -> Validation e a -> () # | |
Semigroup e => Selective (Validation e) |
ExamplesTo understand better, how
When user enters a password in some form, we want to check the following conditions:
As in the previous usage example with form validation, let's introduce a custom data type to represent all possible errors.
And, again, we can implement independent functions to validate all these cases:
And we can easily compose all these checks into single validation for
However, if we try using this function, we can notice a problem immediately:
Due to the nature of the You may say that check for empty password is redundant because empty
password is a special case of a short password. However, when using
This behaviour could be achieved easily if First, we need to write a function that checks whether the password is empty:
Now we can use the
With this implementation we achieved our desired behavior:
|
Defined in Validation select :: Validation e (Either a b) -> Validation e (a -> b) -> Validation e b # | |
(Data e, Data a) => Data (Validation e a) | |
Defined in Validation gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Validation e a -> c (Validation e a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Validation e a) # toConstr :: Validation e a -> Constr # dataTypeOf :: Validation e a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Validation e a)) # dataCast2 :: Typeable t => (forall d e0. (Data d, Data e0) => c (t d e0)) -> Maybe (c (Validation e a)) # gmapT :: (forall b. Data b => b -> b) -> Validation e a -> Validation e a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Validation e a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Validation e a -> r # gmapQ :: (forall d. Data d => d -> u) -> Validation e a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Validation e a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Validation e a -> m (Validation e a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Validation e a -> m (Validation e a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Validation e a -> m (Validation e a) # | |
(Semigroup e, Monoid a) => Monoid (Validation e a) |
Examples
|
Defined in Validation mempty :: Validation e a # mappend :: Validation e a -> Validation e a -> Validation e a # mconcat :: [Validation e a] -> Validation e a # | |
(Semigroup e, Semigroup a) => Semigroup (Validation e a) |
Examples
|
Defined in Validation (<>) :: Validation e a -> Validation e a -> Validation e a # sconcat :: NonEmpty (Validation e a) -> Validation e a # stimes :: Integral b => b -> Validation e a -> Validation e a # | |
Generic (Validation e a) | |
Defined in Validation type Rep (Validation e a) :: Type -> Type # from :: Validation e a -> Rep (Validation e a) x # to :: Rep (Validation e a) x -> Validation e a # | |
(Show e, Show a) => Show (Validation e a) | |
Defined in Validation showsPrec :: Int -> Validation e a -> ShowS # show :: Validation e a -> String # showList :: [Validation e a] -> ShowS # | |
(NFData e, NFData a) => NFData (Validation e a) | |
Defined in Validation rnf :: Validation e a -> () # | |
(Eq e, Eq a) => Eq (Validation e a) | |
Defined in Validation (==) :: Validation e a -> Validation e a -> Bool # (/=) :: Validation e a -> Validation e a -> Bool # | |
(Ord e, Ord a) => Ord (Validation e a) | |
Defined in Validation compare :: Validation e a -> Validation e a -> Ordering # (<) :: Validation e a -> Validation e a -> Bool # (<=) :: Validation e a -> Validation e a -> Bool # (>) :: Validation e a -> Validation e a -> Bool # (>=) :: Validation e a -> Validation e a -> Bool # max :: Validation e a -> Validation e a -> Validation e a # min :: Validation e a -> Validation e a -> Validation e a # | |
type Rep1 (Validation e :: Type -> Type) | |
Defined in Validation type Rep1 (Validation e :: Type -> Type) = D1 ('MetaData "Validation" "Validation" "validation-selective-0.2.0.0-HOYmg9lhRsDAJVHD4XoNep" 'False) (C1 ('MetaCons "Failure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 e)) :+: C1 ('MetaCons "Success" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1)) | |
type Rep (Validation e a) | |
Defined in Validation type Rep (Validation e a) = D1 ('MetaData "Validation" "Validation" "validation-selective-0.2.0.0-HOYmg9lhRsDAJVHD4XoNep" 'False) (C1 ('MetaCons "Failure" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 e)) :+: C1 ('MetaCons "Success" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a))) |
failure :: e -> Validation (NonEmpty e) a #
successes :: [Validation e a] -> [a] #
Filters out all Success
values into the new list of a
s from the given
list of Validation
s.
Note that the order is preserved.
>>>
successes [Failure "Hello", Success 1, Failure "world", Success 2, Failure "!" ]
[1,2]
failures :: [Validation e a] -> [e] #
Filters out all Failure
values into the new list of e
s from the given
list of Validation
s.
Note that the order is preserved.
>>>
failures [Failure "Hello", Success 1, Failure "world", Success 2, Failure "!" ]
["Hello","world","!"]
traverseValidate :: forall t a err b. Traversable t => (a -> Either err b) -> t a -> Either (NonEmpty err) (t b) Source #
traverse
with a function returning Either
and collect all errors that happen, if they happen.
Does not shortcut on error, so will always traverse the whole list/Traversable
structure.
This is a useful error handling function in many circumstances, because it won’t only return the first error that happens, but rather all of them.
traverseValidateM :: forall t m a err b. (Traversable t, Applicative m) => (a -> m (Either err b)) -> t a -> m (Either (NonEmpty err) (t b)) Source #
traverse
with a function returning 'm Either' and collect all errors that happen, if they happen.
Does not shortcut on error, so will always traverse the whole list/Traversable
structure.
This is a useful error handling function in many circumstances, because it won’t only return the first error that happens, but rather all of them.
traverseValidateM_ :: forall t m a err. (Traversable t, Applicative m) => (a -> m (Either err ())) -> t a -> m (Either (NonEmpty err) ()) Source #
traverse_
with a function returning 'm Either' and collect all errors that happen, if they happen.
Does not shortcut on error, so will always traverse the whole list/Traversable
structure.
This is a useful error handling function in many circumstances, because it won’t only return the first error that happens, but rather all of them.
eitherToValidation :: Either e a -> Validation e a #
Transform an Either
into a Validation
.
>>>
eitherToValidation (Right "whoop")
Success "whoop"
>>>
eitherToValidation (Left "nahh")
Failure "nahh"
eitherToListValidation :: Either a c -> Validation (NonEmpty a) c Source #
Like eitherToValidation
, but puts the Error side into a NonEmpty list
to make it combine with other validations.
See also validateEithers
, if you have a list of Either and want to collect all errors.
validationToEither :: Validation e a -> Either e a #
Transform a Validation
into an Either
.
>>>
validationToEither (Success "whoop")
Right "whoop"
>>>
validationToEither (Failure "nahh")
Left "nahh"
The These
type represents values with two non-exclusive possibilities.
This can be useful to represent combinations of two values, where the
combination is defined if either input is. Algebraically, the type
represents These
A B(A + B + AB)
, which doesn't factor easily into
sums and products--a type like
is unclear and
awkward to use.Either
A (B, Maybe
A)
These
has straightforward instances of Functor
, Monad
, &c., and
behaves like a hybrid error/writer monad, as would be expected.
For zipping and unzipping of structures with These
values, see
Data.Align.
Instances
Assoc These | Since: these-0.8 |
Swap These | Since: these-0.8 |
Defined in Data.These | |
Bifoldable These | |
Bifunctor These | |
Bitraversable These | |
Defined in Data.These bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) # | |
Eq2 These | Since: these-1.1.1 |
Ord2 These | Since: these-1.1.1 |
Defined in Data.These | |
Read2 These | Since: these-1.1.1 |
Defined in Data.These liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (These a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [These a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (These a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [These a b] # | |
Show2 These | Since: these-1.1.1 |
NFData2 These | Since: these-1.1.1 |
Defined in Data.These | |
Bifoldable1 These | Since: these-1.2 |
Defined in Data.These | |
Hashable2 These | Since: these-1.1.1 |
Defined in Data.These | |
Generic1 (These a :: Type -> Type) | |
Foldable (These a) | |
Defined in Data.These fold :: Monoid m => These a m -> m # foldMap :: Monoid m => (a0 -> m) -> These a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> These a a0 -> m # foldr :: (a0 -> b -> b) -> b -> These a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> These a a0 -> b # foldl :: (b -> a0 -> b) -> b -> These a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> These a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> These a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> These a a0 -> a0 # toList :: These a a0 -> [a0] # elem :: Eq a0 => a0 -> These a a0 -> Bool # maximum :: Ord a0 => These a a0 -> a0 # minimum :: Ord a0 => These a a0 -> a0 # | |
Eq a => Eq1 (These a) | Since: these-1.1.1 |
Ord a => Ord1 (These a) | Since: these-1.1.1 |
Defined in Data.These | |
Read a => Read1 (These a) | Since: these-1.1.1 |
Defined in Data.These | |
Show a => Show1 (These a) | Since: these-1.1.1 |
Traversable (These a) | |
Semigroup a => Applicative (These a) | |
Functor (These a) | |
Semigroup a => Monad (These a) | |
NFData a => NFData1 (These a) | Since: these-1.1.1 |
Defined in Data.These | |
Hashable a => Hashable1 (These a) | Since: these-1.1.1 |
Defined in Data.These | |
(Data a, Data b) => Data (These a b) | |
Defined in Data.These gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> These a b -> c (These a b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (These a b) # toConstr :: These a b -> Constr # dataTypeOf :: These a b -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (These a b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (These a b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> These a b -> These a b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> These a b -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> These a b -> r # gmapQ :: (forall d. Data d => d -> u) -> These a b -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> These a b -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) # | |
(Semigroup a, Semigroup b) => Semigroup (These a b) | |
Generic (These a b) | |
(Read a, Read b) => Read (These a b) | |
(Show a, Show b) => Show (These a b) | |
(Binary a, Binary b) => Binary (These a b) | Since: these-0.7.1 |
(NFData a, NFData b) => NFData (These a b) | Since: these-0.7.1 |
Defined in Data.These | |
(Eq a, Eq b) => Eq (These a b) | |
(Ord a, Ord b) => Ord (These a b) | |
Defined in Data.These | |
(Hashable a, Hashable b) => Hashable (These a b) | |
Defined in Data.These | |
type Rep1 (These a :: Type -> Type) | |
Defined in Data.These type Rep1 (These a :: Type -> Type) = D1 ('MetaData "These" "Data.These" "these-1.2-UBdGAEuHN58xE7uqj4k9i" 'False) (C1 ('MetaCons "This" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: (C1 ('MetaCons "That" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1) :+: C1 ('MetaCons "These" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))) | |
type Rep (These a b) | |
Defined in Data.These type Rep (These a b) = D1 ('MetaData "These" "Data.These" "these-1.2-UBdGAEuHN58xE7uqj4k9i" 'False) (C1 ('MetaCons "This" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: (C1 ('MetaCons "That" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b)) :+: C1 ('MetaCons "These" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b)))) |
eitherToListThese :: Either err a -> These (NonEmpty err) a Source #
Like eitherToThese
, but puts the Error side into a NonEmpty list
to make it combine with other theses.
validationToThese :: Validation err a -> These err a Source #
Convert a Validation
to a These
.
thenThese :: (Monad m, Semigroup err) => (a -> m (These err b)) -> m (These err a) -> m (These err b) Source #
thenValidate :: (a -> Validation err b) -> Validation err a -> Validation err b Source #
Nested validating bind-like combinator.
Use if you want to collect errors, and want to chain multiple functions returning Validation
.
thenValidateM :: Monad m => (a -> m (Validation err b)) -> m (Validation err a) -> m (Validation err b) Source #
Nested validating bind-like combinator inside some other m
.
Use if you want to collect errors, and want to chain multiple functions returning Validation
.
Non-empty (and non-strict) list type.
Since: base-4.9.0.0
a :| [a] infixr 5 |
Instances
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 |
Comonad NonEmpty | |
ComonadApply NonEmpty | |
Foldable1 NonEmpty | |
Defined in Data.Foldable1 fold1 :: Semigroup m => NonEmpty m -> m # foldMap1 :: Semigroup m => (a -> m) -> NonEmpty a -> m # foldMap1' :: Semigroup m => (a -> m) -> NonEmpty a -> m # toNonEmpty :: NonEmpty a -> NonEmpty a # maximum :: Ord a => NonEmpty a -> a # minimum :: Ord a => NonEmpty a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b # | |
Hashable1 NonEmpty | Since: hashable-1.3.1.0 |
Defined in Data.Hashable.Class | |
Alt NonEmpty | |
Apply NonEmpty | |
Bind NonEmpty | |
Extend NonEmpty | |
Traversable1 NonEmpty | |
Generic1 NonEmpty | |
Lift a => Lift (NonEmpty a :: Type) | Since: template-haskell-2.15.0.0 |
Data a => Data (NonEmpty a) | Since: base-4.9.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NonEmpty a -> c (NonEmpty a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NonEmpty a) # toConstr :: NonEmpty a -> Constr # dataTypeOf :: NonEmpty a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (NonEmpty a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NonEmpty a)) # gmapT :: (forall b. Data b => b -> b) -> NonEmpty a -> NonEmpty a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NonEmpty a -> r # gmapQ :: (forall d. Data d => d -> u) -> NonEmpty a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> NonEmpty a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NonEmpty a -> m (NonEmpty a) # | |
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 |
Outputable a => Outputable (NonEmpty a) | |
Defined in GHC.Utils.Outputable | |
Eq a => Eq (NonEmpty a) | Since: base-4.9.0.0 |
Ord a => Ord (NonEmpty a) | Since: base-4.9.0.0 |
Hashable a => Hashable (NonEmpty a) | |
Defined in Data.Hashable.Class | |
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]))) |
nonEmptyDef :: a -> [a] -> NonEmpty a Source #
If the given list is empty, use the given default element and return a non-empty list.
toList :: Foldable t => t a -> [a] #
List of elements of a structure, from left to right. If the entire list is intended to be reduced via a fold, just fold the structure directly bypassing the list.
Examples
Basic usage:
>>>
toList Nothing
[]
>>>
toList (Just 42)
[42]
>>>
toList (Left "foo")
[]
>>>
toList (Node (Leaf 5) 17 (Node Empty 12 (Leaf 8)))
[5,17,12,8]
For lists, toList
is the identity:
>>>
toList [1, 2, 3]
[1,2,3]
Since: base-4.8.0.0
toNonEmptyDefault :: a -> [a] -> NonEmpty a Source #
Construct a non-empty list, given a default value if the ist list was empty.
maximum1 :: (Foldable1 f, Ord a) => f a -> a Source #
O(n)
. Get the maximum element from a non-empty structure.
minimum1 :: (Foldable1 f, Ord a) => f a -> a Source #
O(n)
. Get the minimum element from a non-empty structure.
Boxed vectors, supporting efficient slicing.
Instances
MonadFail Vector | Since: vector-0.12.1.0 |
Defined in Data.Vector | |
MonadFix Vector | This instance has the same semantics as the one for lists. Since: vector-0.12.2.0 |
Defined in Data.Vector | |
MonadZip Vector | |
Foldable Vector | |
Defined in Data.Vector fold :: Monoid m => Vector m -> m # foldMap :: Monoid m => (a -> m) -> Vector a -> m # foldMap' :: Monoid m => (a -> m) -> Vector a -> m # foldr :: (a -> b -> b) -> b -> Vector a -> b # foldr' :: (a -> b -> b) -> b -> Vector a -> b # foldl :: (b -> a -> b) -> b -> Vector a -> b # foldl' :: (b -> a -> b) -> b -> Vector a -> b # foldr1 :: (a -> a -> a) -> Vector a -> a # foldl1 :: (a -> a -> a) -> Vector a -> a # elem :: Eq a => a -> Vector a -> Bool # maximum :: Ord a => Vector a -> a # minimum :: Ord a => Vector a -> a # | |
Eq1 Vector | |
Ord1 Vector | |
Defined in Data.Vector | |
Read1 Vector | |
Defined in Data.Vector | |
Show1 Vector | |
Traversable Vector | |
Alternative Vector | |
Applicative Vector | |
Functor Vector | |
Monad Vector | |
MonadPlus Vector | |
NFData1 Vector | Since: vector-0.12.1.0 |
Defined in Data.Vector | |
Vector Vector a | |
Defined in Data.Vector basicUnsafeFreeze :: Mutable Vector s a -> ST s (Vector a) # basicUnsafeThaw :: Vector a -> ST s (Mutable Vector s a) # basicLength :: Vector a -> Int # basicUnsafeSlice :: Int -> Int -> Vector a -> Vector a # basicUnsafeIndexM :: Vector a -> Int -> Box a # basicUnsafeCopy :: Mutable Vector s a -> Vector a -> ST s () # | |
Data a => Data (Vector a) | |
Defined in Data.Vector gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Vector a -> c (Vector a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Vector a) # toConstr :: Vector a -> Constr # dataTypeOf :: Vector a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Vector a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Vector a)) # gmapT :: (forall b. Data b => b -> b) -> Vector a -> Vector a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Vector a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Vector a -> r # gmapQ :: (forall d. Data d => d -> u) -> Vector a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Vector a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Vector a -> m (Vector a) # | |
Monoid (Vector a) | |
Semigroup (Vector a) | |
IsList (Vector a) | |
Read a => Read (Vector a) | |
Show a => Show (Vector a) | |
NFData a => NFData (Vector a) | |
Defined in Data.Vector | |
Eq a => Eq (Vector a) | |
Ord a => Ord (Vector a) | |
Defined in Data.Vector | |
type Mutable Vector | |
Defined in Data.Vector | |
type Item (Vector a) | |
Defined in Data.Vector |
Representable types of kind *
.
This class is derivable in GHC with the DeriveGeneric
flag on.
A Generic
instance must satisfy the following laws:
from
.to
≡id
to
.from
≡id
Instances
A Lift
instance can have any of its values turned into a Template
Haskell expression. This is needed when a value used within a Template
Haskell quotation is bound outside the Oxford brackets ([| ... |]
or
[|| ... ||]
) but not at the top level. As an example:
add1 :: Int -> Q (TExp Int) add1 x = [|| x + 1 ||]
Template Haskell has no way of knowing what value x
will take on at
splice-time, so it requires the type of x
to be an instance of Lift
.
A Lift
instance must satisfy $(lift x) ≡ x
and $$(liftTyped x) ≡ x
for all x
, where $(...)
and $$(...)
are Template Haskell splices.
It is additionally expected that
.lift
x ≡ unTypeQ
(liftTyped
x)
Lift
instances can be derived automatically by use of the -XDeriveLift
GHC language extension:
{-# LANGUAGE DeriveLift #-} module Foo where import Language.Haskell.TH.Syntax data Bar a = Bar1 a (Bar a) | Bar2 String deriving Lift
Levity-polymorphic since template-haskell-2.16.0.0.
Instances
Lift Addr# | Produces an Since: template-haskell-2.16.0.0 |
Lift Double# | Since: template-haskell-2.16.0.0 |
Lift Float# | Since: template-haskell-2.16.0.0 |
Lift Int# | Since: template-haskell-2.16.0.0 |
Lift Void | Since: template-haskell-2.15.0.0 |
Lift Int16 | |
Lift Int32 | |
Lift Int64 | |
Lift Int8 | |
Lift Word16 | |
Lift Word32 | |
Lift Word64 | |
Lift Word8 | |
Lift ByteString | Since: bytestring-0.11.2.0 |
Defined in Data.ByteString.Internal lift :: Quote m => ByteString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ByteString -> Code m ByteString # | |
Lift ShortByteString | Since: bytestring-0.11.2.0 |
Defined in Data.ByteString.Short.Internal lift :: Quote m => ShortByteString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ShortByteString -> Code m ShortByteString # | |
Lift ByteArray | |
Lift Scientific | Since: scientific-0.3.7.0 |
Defined in Data.Scientific lift :: Quote m => Scientific -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Scientific -> Code m Scientific # | |
Lift Integer | |
Lift Natural | |
Lift () | |
Lift Bool | |
Lift Char | |
Lift Double | |
Lift Float | |
Lift Int | |
Lift Word | |
Lift Char# | Since: template-haskell-2.16.0.0 |
Lift Word# | Since: template-haskell-2.16.0.0 |
Integral a => Lift (Ratio a :: Type) | |
Lift a => Lift (Array a :: Type) | |
Lift a => Lift (HashSet a :: TYPE LiftedRep) | Since: unordered-containers-0.2.17.0 |
Lift a => Lift (NonEmpty a :: Type) | Since: template-haskell-2.15.0.0 |
Lift a => Lift (Maybe a :: Type) | |
Lift a => Lift ([a] :: Type) | |
(Lift a, Lift b) => Lift (Either a b :: Type) | |
(Lift k, Lift v) => Lift (HashMap k v :: Type) | Since: unordered-containers-0.2.17.0 |
(Lift k, Lift v) => Lift (Leaf k v :: Type) | Since: unordered-containers-0.2.17.0 |
(Lift a, Lift b) => Lift ((a, b) :: Type) | |
(Lift a, Lift b, Lift c) => Lift ((a, b, c) :: Type) | |
(Lift a, Lift b, Lift c, Lift d) => Lift ((a, b, c, d) :: Type) | |
(Lift a, Lift b, Lift c, Lift d, Lift e) => Lift ((a, b, c, d, e) :: Type) | |
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f) => Lift ((a, b, c, d, e, f) :: Type) | |
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g) => Lift ((a, b, c, d, e, f, g) :: Type) | |
Lift ByteString | |
Defined in Data.ByteString.Lazy.Internal lift :: Quote m => ByteString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ByteString -> Code m ByteString # | |
Lift (# #) | Since: template-haskell-2.16.0.0 |
Lift a => Lift ((# a #) :: TYPE ('TupleRep '['BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b) => Lift ((# a | b #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b) => Lift ((# a, b #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c) => Lift ((# a | b | c #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c) => Lift ((# a, b, c #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d) => Lift ((# a | b | c | d #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d) => Lift ((# a, b, c, d #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d, Lift e) => Lift ((# a | b | c | d | e #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d, Lift e) => Lift ((# a, b, c, d, e #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f) => Lift ((# a | b | c | d | e | f #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f) => Lift ((# a, b, c, d, e, f #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g) => Lift ((# a | b | c | d | e | f | g #) :: TYPE ('SumRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
(Lift a, Lift b, Lift c, Lift d, Lift e, Lift f, Lift g) => Lift ((# a, b, c, d, e, f, g #) :: TYPE ('TupleRep '['BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted, 'BoxedRep 'Lifted])) | Since: template-haskell-2.16.0.0 |
The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
Since: base-4.9.0.0
Instances
Semigroup All | Since: base-4.9.0.0 |
Semigroup Any | Since: base-4.9.0.0 |
Semigroup Void | Since: base-4.9.0.0 |
Semigroup Builder | |
Semigroup ByteString | |
Defined in Data.ByteString.Internal (<>) :: ByteString -> ByteString -> ByteString # sconcat :: NonEmpty ByteString -> ByteString # stimes :: Integral b => b -> ByteString -> ByteString # | |
Semigroup ByteString | |
Defined in Data.ByteString.Lazy.Internal (<>) :: ByteString -> ByteString -> ByteString # sconcat :: NonEmpty ByteString -> ByteString # stimes :: Integral b => b -> ByteString -> ByteString # | |
Semigroup ShortByteString | |
Defined in Data.ByteString.Short.Internal (<>) :: ShortByteString -> ShortByteString -> ShortByteString # sconcat :: NonEmpty ShortByteString -> ShortByteString # stimes :: Integral b => b -> ShortByteString -> ShortByteString # | |
Semigroup IntSet | Since: containers-0.5.7 |
Semigroup ByteArray | |
Semigroup UniqueSet | |
Semigroup LabelSet | |
Semigroup Ordering | Since: base-4.9.0.0 |
Semigroup Doc | |
Semigroup () | Since: base-4.9.0.0 |
Semigroup (Comparison a) |
(<>) :: Comparison a -> Comparison a -> Comparison a Comparison cmp <> Comparison cmp' = Comparison a a' -> cmp a a' <> cmp a a' |
Defined in Data.Functor.Contravariant (<>) :: Comparison a -> Comparison a -> Comparison a # sconcat :: NonEmpty (Comparison a) -> Comparison a # stimes :: Integral b => b -> Comparison a -> Comparison a # | |
Semigroup (Equivalence a) |
(<>) :: Equivalence a -> Equivalence a -> Equivalence a Equivalence equiv <> Equivalence equiv' = Equivalence a b -> equiv a b && equiv a b |
Defined in Data.Functor.Contravariant (<>) :: Equivalence a -> Equivalence a -> Equivalence a # sconcat :: NonEmpty (Equivalence a) -> Equivalence a # stimes :: Integral b => b -> Equivalence a -> Equivalence a # | |
Semigroup (Predicate a) |
(<>) :: Predicate a -> Predicate a -> Predicate a Predicate pred <> Predicate pred' = Predicate a -> pred a && pred' a |
Semigroup a => Semigroup (Identity a) | Since: base-4.9.0.0 |
Semigroup (First a) | Since: base-4.9.0.0 |
Semigroup (Last a) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Down a) | Since: base-4.11.0.0 |
Semigroup (First a) | Since: base-4.9.0.0 |
Semigroup (Last a) | Since: base-4.9.0.0 |
Ord a => Semigroup (Max a) | Since: base-4.9.0.0 |
Ord a => Semigroup (Min a) | Since: base-4.9.0.0 |
Monoid m => Semigroup (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup (<>) :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # sconcat :: NonEmpty (WrappedMonoid m) -> WrappedMonoid m # stimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m # | |
Semigroup a => Semigroup (Dual a) | Since: base-4.9.0.0 |
Semigroup (Endo a) | Since: base-4.9.0.0 |
Num a => Semigroup (Product a) | Since: base-4.9.0.0 |
Num a => Semigroup (Sum a) | Since: base-4.9.0.0 |
Semigroup p => Semigroup (Par1 p) | Since: base-4.12.0.0 |
Semigroup (IntMap a) | Since: containers-0.5.7 |
Semigroup (Seq a) | Since: containers-0.5.7 |
Semigroup (MergeSet a) | |
Ord a => Semigroup (Set a) | Since: containers-0.5.7 |
Semigroup (FromMaybe b) | |
Semigroup a => Semigroup (JoinWith a) | |
Semigroup (NonEmptyDList a) | |
Semigroup a => Semigroup (IO a) | Since: base-4.10.0.0 |
Semigroup (Doc a) | |
Semigroup (Array a) | Since: primitive-0.6.3.0 |
Semigroup a => Semigroup (JoinWith a) | |
Semigroup a => Semigroup (Q a) | Since: template-haskell-2.17.0.0 |
(Hashable a, Eq a) => Semigroup (HashSet a) | \(O(n+m)\) To obtain good performance, the smaller set must be presented as the first argument. Examples
|
Semigroup (Vector a) | |
Semigroup (NonEmpty a) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Maybe a) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (a) | Since: base-4.15 |
Semigroup [a] | Since: base-4.9.0.0 |
Semigroup (Either a b) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Op a b) |
(<>) :: Op a b -> Op a b -> Op a b Op f <> Op g = Op a -> f a <> g a |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Semigroup (U1 p) | Since: base-4.12.0.0 |
Semigroup (V1 p) | Since: base-4.12.0.0 |
Ord k => Semigroup (Map k v) | |
Apply f => Semigroup (Act f a) | |
Alt f => Semigroup (Alt_ f a) | |
(Semigroup a, Semigroup b) => Semigroup (These a b) | |
(Eq k, Hashable k) => Semigroup (HashMap k v) | If a key occurs in both maps, the mapping from the first will be the mapping in the result. Examples
|
(Semigroup e, Semigroup a) => Semigroup (Validation e a) |
Examples
|
Defined in Validation (<>) :: Validation e a -> Validation e a -> Validation e a # sconcat :: NonEmpty (Validation e a) -> Validation e a # stimes :: Integral b => b -> Validation e a -> Validation e a # | |
Semigroup b => Semigroup (a -> b) | Since: base-4.9.0.0 |
(Semigroup a, Semigroup b) => Semigroup (a, b) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Const a b) | Since: base-4.9.0.0 |
(Applicative f, Semigroup a) => Semigroup (Ap f a) | Since: base-4.12.0.0 |
Alternative f => Semigroup (Alt f a) | Since: base-4.9.0.0 |
Semigroup (f p) => Semigroup (Rec1 f p) | Since: base-4.12.0.0 |
Semigroup a => Semigroup (Tagged s a) | |
(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | Since: base-4.9.0.0 |
(Semigroup (f a), Semigroup (g a)) => Semigroup (Product f g a) | Since: base-4.16.0.0 |
(Semigroup (f p), Semigroup (g p)) => Semigroup ((f :*: g) p) | Since: base-4.12.0.0 |
Semigroup c => Semigroup (K1 i c p) | Since: base-4.12.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d) | Since: base-4.9.0.0 |
Semigroup (f (g a)) => Semigroup (Compose f g a) | Since: base-4.16.0.0 |
Semigroup (f (g p)) => Semigroup ((f :.: g) p) | Since: base-4.12.0.0 |
Semigroup (f p) => Semigroup (M1 i c f p) | Since: base-4.12.0.0 |
(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e) | Since: base-4.9.0.0 |
sconcat :: Semigroup a => NonEmpty a -> a #
Reduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
>>>
import Data.List.NonEmpty (NonEmpty (..))
>>>
sconcat $ "Hello" :| [" ", "Haskell", "!"]
"Hello Haskell!"
class Semigroup a => Monoid a #
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.
Instances
Monoid All | Since: base-2.1 |
Monoid Any | Since: base-2.1 |
Monoid Builder | |
Monoid ByteString | |
Defined in Data.ByteString.Internal 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 ByteArray | |
Monoid UniqueSet | |
Monoid LabelSet | |
Monoid Ordering | Since: base-2.1 |
Monoid Doc | |
Monoid () | Since: base-2.1 |
Monoid (Comparison a) |
mempty :: Comparison a mempty = Comparison _ _ -> EQ |
Defined in Data.Functor.Contravariant mempty :: Comparison a # mappend :: Comparison a -> Comparison a -> Comparison a # mconcat :: [Comparison a] -> Comparison a # | |
Monoid (Equivalence a) |
mempty :: Equivalence a mempty = Equivalence _ _ -> True |
Defined in Data.Functor.Contravariant mempty :: Equivalence a # mappend :: Equivalence a -> Equivalence a -> Equivalence a # mconcat :: [Equivalence a] -> Equivalence a # | |
Monoid (Predicate a) |
mempty :: Predicate a mempty = _ -> True |
Monoid a => Monoid (Identity a) | Since: base-4.9.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 (Doc a) | |
Monoid (Array a) | |
Monoid a => Monoid (Q a) | Since: template-haskell-2.17.0.0 |
(Hashable a, Eq a) => Monoid (HashSet a) | \(O(n+m)\) To obtain good performance, the smaller set must be presented as the first argument. Examples
|
Monoid (Vector a) | |
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 a => Monoid (Op a b) |
mempty :: Op a b mempty = Op _ -> mempty |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Monoid (U1 p) | Since: base-4.12.0.0 |
Ord k => Monoid (Map k v) | |
(Eq k, Hashable k) => Monoid (HashMap k v) | If a key occurs in both maps, the mapping from the first will be the mapping in the result. Examples
|
(Semigroup e, Monoid a) => Monoid (Validation e a) |
Examples
|
Defined in Validation mempty :: Validation e a # mappend :: Validation e a -> Validation e a -> Validation e a # mconcat :: [Validation e a] -> Validation e a # | |
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 |
(Semigroup a, Monoid a) => Monoid (Tagged s a) | |
(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 |
mconcat :: Monoid a => [a] -> a #
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!"
ifTrue :: Monoid m => Bool -> m -> m Source #
If the predicate is true, return the m
, else mempty
.
This can be used (together with ifExists
) to e.g. create lists with optional elements:
>>>
import Data.Monoid (Sum(..))
>>>
:{ mconcat [
ifTrue (1 == 1) [1], [2, 3, 4], ifTrue False [5], ] :} [1,2,3,4]
Or any other Monoid:
>>>
mconcat [ Sum 1, ifTrue (1 == 1) (Sum 2), Sum 3 ]
ifExists :: Monoid m => Maybe m -> m Source #
If the given Maybe
is Just
, return the m
, else return mempty.
Uninhabited data type
Since: base-4.8.0.0
Instances
Data Void | Since: base-4.8.0.0 |
Defined in Data.Void gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Void -> c Void # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Void # dataTypeOf :: Void -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Void) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Void) # gmapT :: (forall b. Data b => b -> b) -> Void -> Void # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Void -> r # gmapQ :: (forall d. Data d => d -> u) -> Void -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Void -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Void -> m Void # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Void -> m Void # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Void -> m Void # | |
Semigroup Void | Since: base-4.9.0.0 |
Exception Void | Since: base-4.8.0.0 |
Defined in Data.Void toException :: Void -> SomeException # fromException :: SomeException -> Maybe Void # displayException :: Void -> String # | |
Generic Void | |
Ix Void | Since: base-4.8.0.0 |
Read Void | Reading a Since: base-4.8.0.0 |
Show Void | Since: base-4.8.0.0 |
Eq Void | Since: base-4.8.0.0 |
Ord Void | Since: base-4.8.0.0 |
Hashable Void | |
Defined in Data.Hashable.Class | |
Lift Void | Since: template-haskell-2.15.0.0 |
type Rep Void | Since: base-4.8.0.0 |
Since Void
values logically don't exist, this witnesses the
logical reasoning tool of "ex falso quodlibet".
>>>
let x :: Either Void Int; x = Right 5
>>>
:{
case x of Right r -> r Left l -> absurd l :} 5
Since: base-4.8.0.0
Identity functor and monad. (a non-strict monad)
Since: base-4.8.0.0
Identity | |
|
Instances
MonadFix Identity | Since: base-4.8.0.0 |
Defined in Data.Functor.Identity | |
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 # | |
Eq1 Identity | Since: base-4.9.0.0 |
Ord1 Identity | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 Identity | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 Identity | Since: base-4.9.0.0 |
Traversable Identity | Since: base-4.9.0.0 |
Applicative Identity | Since: base-4.8.0.0 |
Functor Identity | Since: base-4.8.0.0 |
Monad Identity | Since: base-4.8.0.0 |
Comonad Identity | |
ComonadApply Identity | |
Foldable1 Identity | |
Defined in Data.Foldable1 fold1 :: Semigroup m => Identity m -> m # foldMap1 :: Semigroup m => (a -> m) -> Identity a -> m # foldMap1' :: Semigroup m => (a -> m) -> Identity a -> m # toNonEmpty :: Identity a -> NonEmpty a # maximum :: Ord a => Identity a -> a # minimum :: Ord a => Identity a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Identity a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Identity a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Identity a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Identity a -> b # | |
Hashable1 Identity | |
Defined in Data.Hashable.Class | |
Alt Identity | Choose the first option every time. While 'choose the last option' every time is also valid, this instance satisfies more laws. Since: semigroupoids-5.3.6 |
Apply Identity | |
Bind Identity | |
Extend Identity | |
Traversable1 Identity | |
Generic1 Identity | |
Data a => Data (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Identity a -> c (Identity a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Identity a) # toConstr :: Identity a -> Constr # dataTypeOf :: Identity a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Identity a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Identity a)) # gmapT :: (forall b. Data b => b -> b) -> Identity a -> Identity a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Identity a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Identity a -> r # gmapQ :: (forall d. Data d => d -> u) -> Identity a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Identity a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Identity a -> m (Identity a) # | |
Storable a => Storable (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity | |
Monoid a => Monoid (Identity a) | Since: base-4.9.0.0 |
Semigroup a => Semigroup (Identity a) | Since: base-4.9.0.0 |
Bits a => Bits (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity (.&.) :: Identity a -> Identity a -> Identity a # (.|.) :: Identity a -> Identity a -> Identity a # xor :: Identity a -> Identity a -> Identity a # complement :: Identity a -> Identity a # shift :: Identity a -> Int -> Identity a # rotate :: Identity a -> Int -> Identity a # setBit :: Identity a -> Int -> Identity a # clearBit :: Identity a -> Int -> Identity a # complementBit :: Identity a -> Int -> Identity a # testBit :: Identity a -> Int -> Bool # bitSizeMaybe :: Identity a -> Maybe Int # bitSize :: Identity a -> Int # isSigned :: Identity a -> Bool # shiftL :: Identity a -> Int -> Identity a # unsafeShiftL :: Identity a -> Int -> Identity a # shiftR :: Identity a -> Int -> Identity a # unsafeShiftR :: Identity a -> Int -> Identity a # rotateL :: Identity a -> Int -> Identity a # | |
FiniteBits a => FiniteBits (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity finiteBitSize :: Identity a -> Int # countLeadingZeros :: Identity a -> Int # countTrailingZeros :: Identity a -> Int # | |
Bounded a => Bounded (Identity a) | Since: base-4.9.0.0 |
Enum a => Enum (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity succ :: Identity a -> Identity a # pred :: Identity a -> Identity a # fromEnum :: Identity a -> Int # enumFrom :: Identity a -> [Identity a] # enumFromThen :: Identity a -> Identity a -> [Identity a] # enumFromTo :: Identity a -> Identity a -> [Identity a] # enumFromThenTo :: Identity a -> Identity a -> Identity a -> [Identity a] # | |
Floating a => Floating (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity exp :: Identity a -> Identity a # log :: Identity a -> Identity a # sqrt :: Identity a -> Identity a # (**) :: Identity a -> Identity a -> Identity a # logBase :: Identity a -> Identity a -> Identity a # sin :: Identity a -> Identity a # cos :: Identity a -> Identity a # tan :: Identity a -> Identity a # asin :: Identity a -> Identity a # acos :: Identity a -> Identity a # atan :: Identity a -> Identity a # sinh :: Identity a -> Identity a # cosh :: Identity a -> Identity a # tanh :: Identity a -> Identity a # asinh :: Identity a -> Identity a # acosh :: Identity a -> Identity a # atanh :: Identity a -> Identity a # log1p :: Identity a -> Identity a # expm1 :: Identity a -> Identity a # | |
RealFloat a => RealFloat (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity floatRadix :: Identity a -> Integer # floatDigits :: Identity a -> Int # floatRange :: Identity a -> (Int, Int) # decodeFloat :: Identity a -> (Integer, Int) # encodeFloat :: Integer -> Int -> Identity a # exponent :: Identity a -> Int # significand :: Identity a -> Identity a # scaleFloat :: Int -> Identity a -> Identity a # isInfinite :: Identity a -> Bool # isDenormalized :: Identity a -> Bool # isNegativeZero :: Identity a -> Bool # | |
Generic (Identity a) | |
Ix a => Ix (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity range :: (Identity a, Identity a) -> [Identity a] # index :: (Identity a, Identity a) -> Identity a -> Int # unsafeIndex :: (Identity a, Identity a) -> Identity a -> Int # inRange :: (Identity a, Identity a) -> Identity a -> Bool # rangeSize :: (Identity a, Identity a) -> Int # unsafeRangeSize :: (Identity a, Identity a) -> Int # | |
Num a => Num (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity | |
Read a => Read (Identity a) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Fractional a => Fractional (Identity a) | Since: base-4.9.0.0 |
Integral a => Integral (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity quot :: Identity a -> Identity a -> Identity a # rem :: Identity a -> Identity a -> Identity a # div :: Identity a -> Identity a -> Identity a # mod :: Identity a -> Identity a -> Identity a # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) # divMod :: Identity a -> Identity a -> (Identity a, Identity a) # | |
Real a => Real (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity toRational :: Identity a -> Rational # | |
RealFrac a => RealFrac (Identity a) | Since: base-4.9.0.0 |
Show a => Show (Identity a) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
Eq a => Eq (Identity a) | Since: base-4.8.0.0 |
Ord a => Ord (Identity a) | Since: base-4.8.0.0 |
Hashable a => Hashable (Identity a) | |
Defined in Data.Hashable.Class | |
type Rep1 Identity | Since: base-4.8.0.0 |
Defined in Data.Functor.Identity | |
type Rep (Identity a) | Since: base-4.8.0.0 |
Defined in Data.Functor.Identity |
Natural number
Invariant: numbers <= 0xffffffffffffffff use the NS
constructor
Instances
Data Natural | Since: base-4.8.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Natural -> c Natural # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Natural # toConstr :: Natural -> Constr # dataTypeOf :: Natural -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Natural) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Natural) # gmapT :: (forall b. Data b => b -> b) -> Natural -> Natural # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r # gmapQ :: (forall d. Data d => d -> u) -> Natural -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Natural -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Natural -> m Natural # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural # | |
Enum Natural | Since: base-4.8.0.0 |
Ix Natural | Since: base-4.8.0.0 |
Num Natural | Note that Since: base-4.8.0.0 |
Read Natural | Since: base-4.8.0.0 |
Integral Natural | Since: base-4.8.0.0 |
Defined in GHC.Real | |
Real Natural | Since: base-4.8.0.0 |
Defined in GHC.Real toRational :: Natural -> Rational # | |
Show Natural | Since: base-4.8.0.0 |
Eq Natural | |
Ord Natural | |
Hashable Natural | |
Defined in Data.Hashable.Class | |
Lift Natural | |
type PyFClassify Natural | |
Defined in PyF.Class |
intToNatural :: Integral a => a -> Maybe Natural Source #
Convert an integer to a Natural
if possible
Named the same as the function from GHC.Natural, but does not crash.
data Scientific #
An arbitrary-precision number represented using scientific notation.
This type describes the set of all
which have a finite
decimal expansion.Real
s
A scientific number with coefficient
c
and base10Exponent
e
corresponds to the Fractional
number: fromInteger
c * 10 ^^
e
Instances
Data Scientific | |
Defined in Data.Scientific gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Scientific -> c Scientific # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Scientific # toConstr :: Scientific -> Constr # dataTypeOf :: Scientific -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Scientific) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Scientific) # gmapT :: (forall b. Data b => b -> b) -> Scientific -> Scientific # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Scientific -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Scientific -> r # gmapQ :: (forall d. Data d => d -> u) -> Scientific -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Scientific -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Scientific -> m Scientific # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Scientific -> m Scientific # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Scientific -> m Scientific # | |
Num Scientific | WARNING: |
Defined in Data.Scientific (+) :: Scientific -> Scientific -> Scientific # (-) :: Scientific -> Scientific -> Scientific # (*) :: Scientific -> Scientific -> Scientific # negate :: Scientific -> Scientific # abs :: Scientific -> Scientific # signum :: Scientific -> Scientific # fromInteger :: Integer -> Scientific # | |
Read Scientific | Supports the skipping of parentheses and whitespaces. Example: > read " ( (( -1.0e+3 ) ))" :: Scientific -1000.0 (Note: This |
Defined in Data.Scientific readsPrec :: Int -> ReadS Scientific # readList :: ReadS [Scientific] # readPrec :: ReadPrec Scientific # readListPrec :: ReadPrec [Scientific] # | |
Fractional Scientific | WARNING: These methods also compute
|
Defined in Data.Scientific (/) :: Scientific -> Scientific -> Scientific # recip :: Scientific -> Scientific # fromRational :: Rational -> Scientific # | |
Real Scientific | WARNING: Avoid applying |
Defined in Data.Scientific toRational :: Scientific -> Rational # | |
RealFrac Scientific | WARNING: the methods of the |
Defined in Data.Scientific properFraction :: Integral b => Scientific -> (b, Scientific) # truncate :: Integral b => Scientific -> b # round :: Integral b => Scientific -> b # ceiling :: Integral b => Scientific -> b # floor :: Integral b => Scientific -> b # | |
Show Scientific | See |
Defined in Data.Scientific showsPrec :: Int -> Scientific -> ShowS # show :: Scientific -> String # showList :: [Scientific] -> ShowS # | |
Binary Scientific | Note that in the future I intend to change the type of the |
Defined in Data.Scientific | |
NFData Scientific | |
Defined in Data.Scientific rnf :: Scientific -> () # | |
Eq Scientific | Scientific numbers can be safely compared for equality. No magnitude |
Defined in Data.Scientific (==) :: Scientific -> Scientific -> Bool # (/=) :: Scientific -> Scientific -> Bool # | |
Ord Scientific | Scientific numbers can be safely compared for ordering. No magnitude |
Defined in Data.Scientific compare :: Scientific -> Scientific -> Ordering # (<) :: Scientific -> Scientific -> Bool # (<=) :: Scientific -> Scientific -> Bool # (>) :: Scientific -> Scientific -> Bool # (>=) :: Scientific -> Scientific -> Bool # max :: Scientific -> Scientific -> Scientific # min :: Scientific -> Scientific -> Scientific # | |
Hashable Scientific | A hash can be safely calculated from a
|
Defined in Data.Scientific hashWithSalt :: Int -> Scientific -> Int # hash :: Scientific -> Int # | |
Lift Scientific | Since: scientific-0.3.7.0 |
Defined in Data.Scientific lift :: Quote m => Scientific -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => Scientific -> Code m Scientific # |
class Contravariant (f :: Type -> Type) #
The class of contravariant functors.
Whereas in Haskell, one can think of a Functor
as containing or producing
values, a contravariant functor is a functor that can be thought of as
consuming values.
As an example, consider the type of predicate functions a -> Bool
. One
such predicate might be negative x = x < 0
, which
classifies integers as to whether they are negative. However, given this
predicate, we can re-use it in other situations, providing we have a way to
map values to integers. For instance, we can use the negative
predicate
on a person's bank balance to work out if they are currently overdrawn:
newtype Predicate a = Predicate { getPredicate :: a -> Bool } instance Contravariant Predicate where contramap :: (a' -> a) -> (Predicate a -> Predicate a') contramap f (Predicate p) = Predicate (p . f) | `- First, map the input... `----- then apply the predicate. overdrawn :: Predicate Person overdrawn = contramap personBankBalance negative
Any instance should be subject to the following laws:
Note, that the second law follows from the free theorem of the type of
contramap
and the first law, so you need only check that the former
condition holds.
Instances
contramap :: Contravariant f => (a' -> a) -> f a -> f a' #
(>$<) :: Contravariant f => (a -> b) -> f b -> f a infixl 4 #
This is an infix alias for contramap
.
(>&<) :: Contravariant f => f b -> (a -> b) -> f a infixl 5 Source #
class Profunctor (p :: Type -> Type -> Type) #
Formally, the class Profunctor
represents a profunctor
from Hask
-> Hask
.
Intuitively it is a bifunctor where the first argument is contravariant and the second argument is covariant.
You can define a Profunctor
by either defining dimap
or by defining both
lmap
and rmap
.
If you supply dimap
, you should ensure that:
dimap
id
id
≡id
If you supply lmap
and rmap
, ensure:
lmap
id
≡id
rmap
id
≡id
If you supply both, you should also ensure:
dimap
f g ≡lmap
f.
rmap
g
These ensure by parametricity:
dimap
(f.
g) (h.
i) ≡dimap
g h.
dimap
f ilmap
(f.
g) ≡lmap
g.
lmap
frmap
(f.
g) ≡rmap
f.
rmap
g
Instances
Monad m => Profunctor (Kleisli m) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Kleisli m b c -> Kleisli m a d # lmap :: (a -> b) -> Kleisli m b c -> Kleisli m a c # rmap :: (b -> c) -> Kleisli m a b -> Kleisli m a c # (#.) :: forall a b c q. Coercible c b => q b c -> Kleisli m a b -> Kleisli m a c # (.#) :: forall a b c q. Coercible b a => Kleisli m b c -> q a b -> Kleisli m a c # | |
Profunctor (Tagged :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Tagged b c -> Tagged a d # lmap :: (a -> b) -> Tagged b c -> Tagged a c # rmap :: (b -> c) -> Tagged a b -> Tagged a c # (#.) :: forall a b c q. Coercible c b => q b c -> Tagged a b -> Tagged a c # (.#) :: forall a b c q. Coercible b a => Tagged b c -> q a b -> Tagged a c # | |
Functor w => Profunctor (Cokleisli w) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Cokleisli w b c -> Cokleisli w a d # lmap :: (a -> b) -> Cokleisli w b c -> Cokleisli w a c # rmap :: (b -> c) -> Cokleisli w a b -> Cokleisli w a c # (#.) :: forall a b c q. Coercible c b => q b c -> Cokleisli w a b -> Cokleisli w a c # (.#) :: forall a b c q. Coercible b a => Cokleisli w b c -> q a b -> Cokleisli w a c # | |
Profunctor (->) | |
Defined in Data.Profunctor.Unsafe | |
Contravariant f => Profunctor (Clown f :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Clown f b c -> Clown f a d # lmap :: (a -> b) -> Clown f b c -> Clown f a c # rmap :: (b -> c) -> Clown f a b -> Clown f a c # (#.) :: forall a b c q. Coercible c b => q b c -> Clown f a b -> Clown f a c # (.#) :: forall a b c q. Coercible b a => Clown f b c -> q a b -> Clown f a c # | |
Functor f => Profunctor (Joker f :: Type -> Type -> Type) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Joker f b c -> Joker f a d # lmap :: (a -> b) -> Joker f b c -> Joker f a c # rmap :: (b -> c) -> Joker f a b -> Joker f a c # (#.) :: forall a b c q. Coercible c b => q b c -> Joker f a b -> Joker f a c # (.#) :: forall a b c q. Coercible b a => Joker f b c -> q a b -> Joker f a c # | |
(Profunctor p, Profunctor q) => Profunctor (Product p q) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Product p q b c -> Product p q a d # lmap :: (a -> b) -> Product p q b c -> Product p q a c # rmap :: (b -> c) -> Product p q a b -> Product p q a c # (#.) :: forall a b c q0. Coercible c b => q0 b c -> Product p q a b -> Product p q a c # (.#) :: forall a b c q0. Coercible b a => Product p q b c -> q0 a b -> Product p q a c # | |
(Profunctor p, Profunctor q) => Profunctor (Sum p q) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Sum p q b c -> Sum p q a d # lmap :: (a -> b) -> Sum p q b c -> Sum p q a c # rmap :: (b -> c) -> Sum p q a b -> Sum p q a c # (#.) :: forall a b c q0. Coercible c b => q0 b c -> Sum p q a b -> Sum p q a c # (.#) :: forall a b c q0. Coercible b a => Sum p q b c -> q0 a b -> Sum p q a c # | |
(Functor f, Profunctor p) => Profunctor (Tannen f p) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Tannen f p b c -> Tannen f p a d # lmap :: (a -> b) -> Tannen f p b c -> Tannen f p a c # rmap :: (b -> c) -> Tannen f p a b -> Tannen f p a c # (#.) :: forall a b c q. Coercible c b => q b c -> Tannen f p a b -> Tannen f p a c # (.#) :: forall a b c q. Coercible b a => Tannen f p b c -> q a b -> Tannen f p a c # | |
(Profunctor p, Functor f, Functor g) => Profunctor (Biff p f g) | |
Defined in Data.Profunctor.Unsafe dimap :: (a -> b) -> (c -> d) -> Biff p f g b c -> Biff p f g a d # lmap :: (a -> b) -> Biff p f g b c -> Biff p f g a c # rmap :: (b -> c) -> Biff p f g a b -> Biff p f g a c # (#.) :: forall a b c q. Coercible c b => q b c -> Biff p f g a b -> Biff p f g a c # (.#) :: forall a b c q. Coercible b a => Biff p f g b c -> q a b -> Biff p f g a c # |
dimap :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d #
lmap :: Profunctor p => (a -> b) -> p b c -> p a c #
rmap :: Profunctor p => (b -> c) -> p a b -> p a c #
class Semigroupoid (c :: k -> k -> Type) #
Instances
Semigroupoid Op | |
Semigroupoid (,) | http://en.wikipedia.org/wiki/Band_(mathematics)#Rectangular_bands |
Defined in Data.Semigroupoid | |
Bind m => Semigroupoid (Kleisli m :: Type -> Type -> TYPE LiftedRep) | |
Semigroupoid (Const :: Type -> Type -> Type) | |
Semigroupoid (Tagged :: Type -> Type -> Type) | |
Semigroupoid (Coercion :: k -> k -> Type) | |
Semigroupoid ((:~:) :: k -> k -> Type) | |
Extend w => Semigroupoid (Cokleisli w :: Type -> Type -> TYPE LiftedRep) | |
Semigroupoid (->) | |
Defined in Data.Semigroupoid | |
Semigroupoid ((:~~:) :: k -> k -> Type) | |
Semigroup m => Semigroupoid (Semi m :: k -> k -> Type) | |
Category k2 => Semigroupoid (WrappedCategory k2 :: k1 -> k1 -> Type) | |
Defined in Data.Semigroupoid o :: forall (j :: k) (k10 :: k) (i :: k). WrappedCategory k2 j k10 -> WrappedCategory k2 i j -> WrappedCategory k2 i k10 # |
class Category (cat :: k -> k -> Type) #
A class for categories. Instances should satisfy the laws
Instances
Category Op | |
Monad m => Category (Kleisli m :: Type -> Type -> TYPE LiftedRep) | Since: base-3.0 |
(Applicative f, Monad f) => Category (WhenMissing f :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal id :: forall (a :: k). WhenMissing f a a # (.) :: forall (b :: k) (c :: k) (a :: k). WhenMissing f b c -> WhenMissing f a b -> WhenMissing f a c # | |
Category (Coercion :: k -> k -> Type) | Since: base-4.7.0.0 |
Category ((:~:) :: k -> k -> Type) | Since: base-4.7.0.0 |
Comonad w => Category (Cokleisli w :: Type -> Type -> TYPE LiftedRep) | |
(Monad f, Applicative f) => Category (WhenMatched f x :: Type -> Type -> TYPE LiftedRep) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal id :: forall (a :: k). WhenMatched f x a a # (.) :: forall (b :: k) (c :: k) (a :: k). WhenMatched f x b c -> WhenMatched f x a b -> WhenMatched f x a c # | |
(Applicative f, Monad f) => Category (WhenMissing f k :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.Map.Internal id :: forall (a :: k0). WhenMissing f k a a # (.) :: forall (b :: k0) (c :: k0) (a :: k0). WhenMissing f k b c -> WhenMissing f k a b -> WhenMissing f k a c # | |
Category (->) | Since: base-3.0 |
Defined in Control.Category | |
Category ((:~~:) :: k -> k -> Type) | Since: base-4.10.0.0 |
(Monad f, Applicative f) => Category (WhenMatched f k x :: Type -> Type -> TYPE LiftedRep) | Since: containers-0.5.9 |
Defined in Data.Map.Internal id :: forall (a :: k0). WhenMatched f k x a a # (.) :: forall (b :: k0) (c :: k0) (a :: k0). WhenMatched f k x b c -> WhenMatched f k x a b -> WhenMatched f k x a c # | |
Monoid m => Category (Semi m :: k -> k -> Type) | |
Category k2 => Category (WrappedCategory k2 :: k1 -> k1 -> Type) | |
Defined in Data.Semigroupoid id :: forall (a :: k). WrappedCategory k2 a a # (.) :: forall (b :: k) (c :: k) (a :: k). WrappedCategory k2 b c -> WrappedCategory k2 a b -> WrappedCategory k2 a c # | |
(Category p, Category q) => Category (Product p q :: k -> k -> Type) | |
(Applicative f, Category p) => Category (Tannen f p :: k -> k -> Type) | |
(>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c infixr 1 #
Left-to-right composition
(&>>) :: Semigroupoid s => s a b -> s b c -> s a c infixr 1 Source #
Forward semigroupoid application. The same as (>>>)
, but Semigroupoid
is not a superclass of Category
(yet).
Specialized examples:
@
for functions : (a -> b) -> (b -> c) -> (a -> c)
for Folds: Fold a b -> Fold b c -> Fold a c
@
type family Any :: k where ... #
The type constructor Any
is type to which you can unsafely coerce any
lifted type, and back. More concretely, for a lifted type t
and
value x :: t
, -- unsafeCoerce (unsafeCoerce x :: Any) :: t
is equivalent
to x
.
Enum definition
inverseFunction :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> k -> Maybe a Source #
inverseFunction f
creates a function that is the inverse of a given function
f
. It does so by constructing Map
internally for each value f a
. The
implementation makes sure that the Map
is constructed only once and then
shared for every call.
Memory usage note: don't inverse functions that have types like Int
as their result. In this case the created Map
will have huge size.
The complexity of reversed mapping is \(\mathcal{O}(\log n)\).
Performance note: make sure to specialize monomorphic type of your functions
that use inverseFunction
to avoid Map
reconstruction.
One of the common inverseFunction
use-case is inverting the show
or a show
-like
function.
>>>
data Color = Red | Green | Blue deriving (Show, Enum, Bounded)
>>>
parse = inverseFunction show :: String -> Maybe Color
>>>
parse "Red"
Just Red>>>
parse "Black"
Nothing
Correctness note: inverseFunction
expects injective function as its argument,
i.e. the function must map distinct arguments to distinct values.
Typical usage of this function looks like this:
@
data GhcVer
= Ghc802
| Ghc822
| Ghc844
| Ghc865
| Ghc881
deriving (Eq
, Ord
, Show
, Enum
, Bounded
)
showGhcVer :: GhcVer -> Text
showGhcVer = \case
Ghc802 -> "8.0.2"
Ghc822 -> "8.2.2"
Ghc844 -> "8.4.4"
Ghc865 -> "8.6.5"
Ghc881 -> "8.8.1"
parseGhcVer :: Text
-> Maybe
GhcVer
parseGhcVer = inverseFunction
showGhcVer
Taken from relude’s Relude.Extra.Enum
.
inverseMap :: forall a k. (Bounded a, Enum a, Ord k) => (a -> k) -> Map k a Source #
Like inverseFunction
, but instead of returning the function
it returns a mapping from all possible outputs to their possible inputs.
This has the same restrictions of inverseFunction
.
enumerateAll :: (Enum a, Bounded a) => [a] Source #
All possible values in this enum.
Map helpers
mapFromListOn :: Ord key => (a -> key) -> [a] -> Map key a Source #
Error handling
type HasCallStack = ?callStack :: CallStack #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack
is an
implementation detail and should not be considered part of the
CallStack
API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
module Data.Error