| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
PossehlAnalyticsPrelude
Synopsis
- data Text
- data ByteString
- data Word8
- fmt :: QuasiQuoter
- textToString :: Text -> String
- stringToText :: String -> Text
- stringToBytesUtf8 :: String -> ByteString
- 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, HasCallStack, 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 (forall a. Functor (p a)) => 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 (forall (m :: Type -> Type). Monad m => Monad (t m)) => 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]
- pattern IsEmpty :: [a]
- pattern IsNonEmpty :: NonEmpty a -> [a]
- singleton :: a -> NonEmpty a
- nonEmpty :: [a] -> Maybe (NonEmpty a)
- nonEmptyDef :: a -> [a] -> NonEmpty a
- overNonEmpty :: Applicative f => (NonEmpty a -> f [b]) -> [a] -> f [b]
- zipNonEmpty :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
- zipWithNonEmpty :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c
- zip3NonEmpty :: NonEmpty a -> NonEmpty b -> NonEmpty c -> NonEmpty (a, b, c)
- zipWith3NonEmpty :: (a -> b -> c -> d) -> NonEmpty a -> NonEmpty b -> NonEmpty c -> NonEmpty d
- zip4NonEmpty :: NonEmpty a -> NonEmpty b -> NonEmpty c -> NonEmpty d -> NonEmpty (a, b, c, d)
- toList :: Foldable t => t a -> [a]
- toNonEmptyDefault :: a -> [a] -> NonEmpty a
- lengthNatural :: Lengthy f => f a -> Natural
- maximum1 :: (Foldable1 f, Ord a) => f a -> a
- minimum1 :: (Foldable1 f, Ord a) => f a -> a
- maximumBy1 :: Foldable1 f => (a -> a -> Ordering) -> f a -> a
- minimumBy1 :: Foldable1 f => (a -> a -> Ordering) -> 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 Methods 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 Methods 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 Methods (.&.) :: Word8 -> Word8 -> Word8 # (.|.) :: Word8 -> Word8 -> Word8 # xor :: Word8 -> Word8 -> Word8 # complement :: Word8 -> Word8 # shift :: Word8 -> Int -> Word8 # rotate :: Word8 -> Int -> Word8 # setBit :: Word8 -> Int -> Word8 # clearBit :: Word8 -> Int -> Word8 # complementBit :: Word8 -> Int -> Word8 # testBit :: Word8 -> Int -> Bool # bitSizeMaybe :: Word8 -> Maybe Int # shiftL :: Word8 -> Int -> Word8 # unsafeShiftL :: Word8 -> Int -> Word8 # shiftR :: Word8 -> Int -> Word8 # unsafeShiftR :: Word8 -> Int -> Word8 # rotateL :: Word8 -> Int -> Word8 # | |
| FiniteBits Word8 | Since: base-4.6.0.0 |
Defined in GHC.Word Methods 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 Methods toRational :: Word8 -> Rational # | |
| Show Word8 | Since: base-2.1 |
| Outputable Word8 | |
Defined in GHC.Utils.Outputable | |
| Eq Word8 | Since: base-2.1 |
| Ord Word8 | Since: base-2.1 |
| Hashable Word8 | |
Defined in Data.Hashable.Class | |
| Uniform Word8 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word8 # | |
| UniformRange Word8 | |
Defined in System.Random.Internal | |
| IArray UArray Word8 | |
Defined in Data.Array.Base Methods 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 Methods 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 #
Convert an (imperformant) list-of-char String into a (performant) Text .
Some libraries (like time or network-uri) still use the String as their interface. We want to convert String to Text as soon as possible and only use Text in our code.
ATTN: Don’t use String in code if you can avoid it, prefer Text instead.
stringToBytesUtf8 :: String -> ByteString 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 #
Make a lazy ByteString strict.
toLazyBytes :: ByteString -> ByteString Source #
Make a strict ByteString lazy.
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.
Minimal complete definition
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 <- Justab <- Justbpure (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}
Since: base-4.18.0.0
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 0Nothing
>>>safeDiv 4 2Just 2
A definition of safeDiv using guards, but not guard:
safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0 = Just (x `div` y)
| otherwise = Nothing
A definition of safeDiv using guard and Monad do-notation:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
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.
Minimal complete definition
Instances
throwM :: (MonadThrow m, HasCallStack, 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:
Minimal complete definition
Instances
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 (MaybeT m) | |
| (Monoid w, MonadReader r m) => MonadReader r (AccumT w m) | Since: mtl-2.3 |
| 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) | Since: mtl-2.3 |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| (Monoid w, MonadReader r m) => MonadReader r (WriterT w m) | |
| MonadReader r' m => MonadReader r' (SelectT r m) | Since: mtl-2.3 |
| MonadReader r ((->) r) | |
| MonadReader r' m => MonadReader r' (ContT r m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | Since: mtl-2.3 |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
| (Monad m, Monoid w) => MonadReader r (RWST r w s m) | |
Arguments
| :: MonadReader r m | |
| => (r -> a) | The selector function to apply to the environment. |
| -> m a |
Retrieves a function of the current environment.
class (forall a. Functor (p a)) => 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. A partially applied Bifunctor
must be a Functor and the second method must agree with fmap.
From this it follows that:
secondid=id
If you supply bimap, you should ensure that:
bimapidid≡id
If you supply first and second, ensure:
firstid≡idsecondid≡id
If you supply both, you should also ensure:
bimapf g ≡firstf.secondg
These ensure by parametricity:
bimap(f.g) (h.i) ≡bimapf h.bimapg ifirst(f.g) ≡firstf.firstgsecond(f.g) ≡secondf.secondg
Since 4.18.0.0 Functor is a superclass of 'Bifunctor.
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 Methods 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 (,) | Class laws for tuples hold only up to laziness. Both
Since: base-4.8.0.0 |
| Bifunctor (Const :: Type -> Type -> Type) | Since: base-4.8.0.0 |
| Bifunctor (Tagged :: Type -> Type -> Type) | |
| Bifunctor (Constant :: 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 Methods 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
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] print1 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 (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) #
The class of monad transformers.
For any monad m, the result t m should also be a monad,
and lift should be a monad transformation from m to t m,
i.e. it should satisfy the following laws:
Since 0.6.0.0 and for GHC 8.6 and later, the requirement that t m
be a Monad is enforced by the implication constraint
forall m. enabled by the
Monad m => Monad (t m)QuantifiedConstraints extension.
Ambiguity error with GHC 9.0 to 9.2.2
These versions of GHC have a bug (https://gitlab.haskell.org/ghc/ghc/-/issues/20582) which causes constraints like
(MonadTrans t, forall m. Monad m => Monad (t m)) => ...
to be reported as ambiguous. For transformers 0.6 and later, this can be fixed by removing the second constraint, which is implied by the first.
Minimal complete definition
Instances
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-0.4.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 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 EitherProxy
>>>Proxy :: Proxy FunctorProxy
>>>Proxy :: Proxy complicatedStructureProxy
Constructors
| Proxy |
Instances
| Generic1 (Proxy :: k -> Type) | |
| Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldMap' :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
| 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 | |
| Data t => Data (Proxy t) | Since: base-4.7.0.0 |
Defined in Data.Data Methods 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 | |
| (Lift k, Lift a) => Lift (Map k a :: Type) | Since: containers-0.6.6 |
| Foldable (Map k) | Folds in order of increasing key. |
Defined in Data.Map.Internal Methods 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) | |
| Hashable k => Hashable1 (Map k) | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
| (Data k, Data a, Ord k) => Data (Map k a) | |
Defined in Data.Map.Internal Methods 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 | |
| ToJExpr a => ToJExpr (Map String a) | |
| (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
Stringerror messages or a validated value of a customUsertype.
- Either list of
Validation(NonEmptyUserValidationError) 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.
Constructors
| Failure e | Validation failure. The |
| Success a | Successful validation result of type |
Instances
| Bifoldable Validation | Similar to Examples
|
Defined in Validation Methods 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 Methods 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 Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Validation a b -> f (Validation c d) # | |
| NFData2 Validation | |
Defined in Validation Methods liftRnf2 :: (a -> ()) -> (b -> ()) -> Validation a b -> () # | |
| Generic1 (Validation e :: Type -> Type) | |
Defined in Validation Associated Types type Rep1 (Validation e) :: k -> Type # Methods 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 Methods 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 Methods 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 Methods 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 Methods 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 Methods 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 Methods (>>=) :: 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 Methods 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 Methods select :: Validation e (Either a b) -> Validation e (a -> b) -> Validation e b # | |
| (Data e, Data a) => Data (Validation e a) | |
Defined in Validation Methods 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 Methods 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 Methods (<>) :: 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 Associated Types type Rep (Validation e a) :: Type -> Type # Methods 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 Methods 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 Methods rnf :: Validation e a -> () # | |
| (Eq e, Eq a) => Eq (Validation e a) | |
Defined in Validation Methods (==) :: 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 Methods 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-D1g4lKwJ88UEPL5hlBGinq" '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-D1g4lKwJ88UEPL5hlBGinq" '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 as from the given
list of Validations.
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 es from the given
list of Validations.
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 | |
| Bifoldable1 These | Since: these-1.2 |
Defined in Data.These | |
| Bifunctor These | |
| Bitraversable These | |
Defined in Data.These Methods 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 Methods 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 | |
| Hashable2 These | Since: these-1.1.1 |
Defined in Data.These | |
| Generic1 (These a :: Type -> Type) | |
| Foldable (These a) | |
Defined in Data.These Methods 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 Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (These a a0) # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [These a a0] # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (These a a0) # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [These a a0] # | |
| 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 Methods 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) | |
| (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.1-LmUgSfNH9g4HQXtMBqinvT" '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.1-LmUgSfNH9g4HQXtMBqinvT" '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
Constructors
| a :| [a] infixr 5 |
Instances
| Foldable NonEmpty | Since: base-4.9.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => NonEmpty m -> m # foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m # foldMap' :: Monoid m => (a -> m) -> NonEmpty a -> m # foldr :: (a -> b -> b) -> b -> NonEmpty a -> b # foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b # foldl :: (b -> a -> b) -> b -> NonEmpty a -> b # foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b # foldr1 :: (a -> a -> a) -> NonEmpty a -> a # foldl1 :: (a -> a -> a) -> NonEmpty a -> a # elem :: Eq a => a -> NonEmpty a -> Bool # maximum :: Ord a => NonEmpty a -> a # minimum :: Ord a => NonEmpty a -> a # | |
| Foldable1 NonEmpty | Since: base-4.18.0.0 |
Defined in Data.Foldable1 Methods fold1 :: Semigroup m => NonEmpty m -> m # foldMap1 :: Semigroup m => (a -> m) -> NonEmpty a -> m # foldMap1' :: Semigroup m => (a -> m) -> NonEmpty a -> m # toNonEmpty :: NonEmpty a -> NonEmpty a # maximum :: Ord a => NonEmpty a -> a # minimum :: Ord a => NonEmpty a -> a # foldrMap1 :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b # foldlMap1' :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b # foldlMap1 :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b # foldrMap1' :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b # | |
| 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 |
| Hashable1 NonEmpty | Since: hashable-1.3.1.0 |
Defined in Data.Hashable.Class | |
| 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 Methods 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 |
| Generic (NonEmpty a) | |
| IsList (NonEmpty a) | Since: base-4.9.0.0 |
| Read a => Read (NonEmpty a) | Since: base-4.11.0.0 |
| Show a => Show (NonEmpty a) | Since: base-4.11.0.0 |
| 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 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 List))) | |
| 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 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]))) | |
| type Item (NonEmpty a) | |
Defined in GHC.IsList | |
pattern IsNonEmpty :: NonEmpty a -> [a] Source #
nonEmptyDef :: a -> [a] -> NonEmpty a Source #
If the given list is empty, use the given default element and return a non-empty list.
overNonEmpty :: Applicative f => (NonEmpty a -> f [b]) -> [a] -> f [b] Source #
If the list is not empty, run the given function with a NonEmpty list, otherwise just return []
zipWithNonEmpty :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c Source #
Zip two non-empty lists, combining them with the given function
zip3NonEmpty :: NonEmpty a -> NonEmpty b -> NonEmpty c -> NonEmpty (a, b, c) Source #
Zip three non-empty lists.
zipWith3NonEmpty :: (a -> b -> c -> d) -> NonEmpty a -> NonEmpty b -> NonEmpty c -> NonEmpty d Source #
Zip three non-empty lists, combining them with the given function
zip4NonEmpty :: NonEmpty a -> NonEmpty b -> NonEmpty c -> NonEmpty d -> NonEmpty (a, b, c, d) Source #
Zip four non-empty lists
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.
lengthNatural :: Lengthy f => f a -> Natural Source #
maximum1 :: (Foldable1 f, Ord a) => f a -> a Source #
O(n). Get the maximum element from a non-empty structure (strict).
minimum1 :: (Foldable1 f, Ord a) => f a -> a Source #
O(n). Get the minimum element from a non-empty structure (strict).
maximumBy1 :: Foldable1 f => (a -> a -> Ordering) -> f a -> a Source #
O(n). Get the maximum element from a non-empty structure, using the given comparator (strict).
minimumBy1 :: Foldable1 f => (a -> a -> Ordering) -> f a -> a Source #
O(n). Get the minimum element from a non-empty structure, using the given comparator (strict).
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 Methods 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 Methods 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 Methods 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≡idto.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 LiftRepresentation-polymorphic since template-haskell-2.16.0.0.
Minimal complete definition
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 ByteArray | Since: template-haskell-2.19.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.Type Methods lift :: Quote m => ByteString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ByteString -> Code m ByteString # | |
| Lift ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods 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 Methods lift :: Quote m => ShortByteString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => ShortByteString -> Code m ShortByteString # | |
| Lift IntSet | Since: containers-0.6.6 |
| Lift OsString | |
| Lift PosixString | |
Defined in System.OsString.Internal.Types Methods lift :: Quote m => PosixString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => PosixString -> Code m PosixString # | |
| Lift WindowsString | |
Defined in System.OsString.Internal.Types Methods lift :: Quote m => WindowsString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => WindowsString -> Code m WindowsString # | |
| Lift OsString | |
| Lift PosixString | |
Defined in System.OsString.Internal.Types Methods lift :: Quote m => PosixString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => PosixString -> Code m PosixString # | |
| Lift WindowsString | |
Defined in System.OsString.Internal.Types Methods lift :: Quote m => WindowsString -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => WindowsString -> Code m WindowsString # | |
| Lift Scientific | Since: scientific-0.3.7.0 |
Defined in Data.Scientific Methods 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 |
| Lift (# #) | Since: template-haskell-2.16.0.0 |
| Lift a => Lift (NonEmpty a :: Type) | Since: template-haskell-2.15.0.0 |
| Integral a => Lift (Ratio a :: Type) | |
| Lift vertex => Lift (SCC vertex :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (IntMap a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (Digit a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (FingerTree a :: Type) | Since: containers-0.6.6 |
Defined in Data.Sequence.Internal Methods lift :: Quote m => FingerTree a -> m Exp # liftTyped :: forall (m :: Type -> Type). Quote m => FingerTree a -> Code m (FingerTree a) # | |
| Lift a => Lift (Node a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (Seq a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (ViewL a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (ViewR a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (Set a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (Tree a :: Type) | Since: containers-0.6.6 |
| Lift a => Lift (Array a :: Type) | |
| Lift a => Lift (HashSet a :: Type) | Since: unordered-containers-0.2.17.0 |
| Lift a => Lift (Maybe a :: Type) | |
| Lift a => Lift ([a] :: Type) | |
| (Lift a, Lift b) => Lift (Either a b :: Type) | |
| (Lift k, Lift a) => Lift (Map k a :: Type) | Since: containers-0.6.6 |
| (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 a => Lift ((# a #) :: TYPE ('TupleRep '[LiftedRep])) | Since: template-haskell-2.16.0.0 |
| (Lift a, Lift b) => Lift ((# a | b #) :: TYPE ('SumRep '[LiftedRep, LiftedRep])) | Since: template-haskell-2.16.0.0 |
| (Lift a, Lift b) => Lift ((# a, b #) :: TYPE ('TupleRep '[LiftedRep, LiftedRep])) | Since: template-haskell-2.16.0.0 |
| (Lift a, Lift b, Lift c) => Lift ((# a | b | c #) :: TYPE ('SumRep '[LiftedRep, LiftedRep, LiftedRep])) | Since: template-haskell-2.16.0.0 |
| (Lift a, Lift b, Lift c) => Lift ((# a, b, c #) :: TYPE ('TupleRep '[LiftedRep, LiftedRep, LiftedRep])) | Since: template-haskell-2.16.0.0 |
| (Lift a, Lift b, Lift c, Lift d) => Lift ((# a | b | c | d #) :: TYPE ('SumRep '[LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | Since: template-haskell-2.16.0.0 |
| (Lift a, Lift b, Lift c, Lift d) => Lift ((# a, b, c, d #) :: TYPE ('TupleRep '[LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | 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 '[LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | 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 '[LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | 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 '[LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | 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 '[LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | 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 '[LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | 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 '[LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep, LiftedRep])) | Since: template-haskell-2.16.0.0 |
The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
You can alternatively define sconcat instead of (<>), in which case the
laws are:
Since: base-4.9.0.0
Instances
| Semigroup Void | Since: base-4.9.0.0 |
| Semigroup ByteString | |
Defined in Data.ByteString.Internal.Type Methods (<>) :: ByteString -> ByteString -> ByteString # sconcat :: NonEmpty ByteString -> ByteString # stimes :: Integral b => b -> ByteString -> ByteString # | |
| Semigroup ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods (<>) :: ByteString -> ByteString -> ByteString # sconcat :: NonEmpty ByteString -> ByteString # stimes :: Integral b => b -> ByteString -> ByteString # | |
| Semigroup ShortByteString | |
Defined in Data.ByteString.Short.Internal Methods (<>) :: ShortByteString -> ShortByteString -> ShortByteString # sconcat :: NonEmpty ShortByteString -> ShortByteString # stimes :: Integral b => b -> ShortByteString -> ShortByteString # | |
| Semigroup IntSet | Since: containers-0.5.7 |
| Semigroup OsString | |
| Semigroup PosixString | |
Defined in System.OsString.Internal.Types Methods (<>) :: PosixString -> PosixString -> PosixString # sconcat :: NonEmpty PosixString -> PosixString # stimes :: Integral b => b -> PosixString -> PosixString # | |
| Semigroup WindowsString | |
Defined in System.OsString.Internal.Types Methods (<>) :: WindowsString -> WindowsString -> WindowsString # sconcat :: NonEmpty WindowsString -> WindowsString # stimes :: Integral b => b -> WindowsString -> WindowsString # | |
| Semigroup UniqueSet | |
| Semigroup LabelSet | |
| Semigroup FastString | |
Defined in GHC.Data.FastString Methods (<>) :: FastString -> FastString -> FastString # sconcat :: NonEmpty FastString -> FastString # stimes :: Integral b => b -> FastString -> FastString # | |
| Semigroup Nablas | |
| Semigroup JStat | |
| Semigroup CIStatic | |
| Semigroup InsideLam | If any occurrence of an identifier is inside a lambda, then the occurrence info of that identifier marks it as occurring inside a lambda |
| Semigroup InterestingCxt | If there is any |
Defined in GHC.Types.Basic Methods (<>) :: InterestingCxt -> InterestingCxt -> InterestingCxt # sconcat :: NonEmpty InterestingCxt -> InterestingCxt # stimes :: Integral b => b -> InterestingCxt -> InterestingCxt # | |
| Semigroup SuccessFlag | |
Defined in GHC.Types.Basic Methods (<>) :: SuccessFlag -> SuccessFlag -> SuccessFlag # sconcat :: NonEmpty SuccessFlag -> SuccessFlag # stimes :: Integral b => b -> SuccessFlag -> SuccessFlag # | |
| Semigroup BufSpan | |
| Semigroup ModuleOrigin | |
Defined in GHC.Unit.State Methods (<>) :: ModuleOrigin -> ModuleOrigin -> ModuleOrigin # sconcat :: NonEmpty ModuleOrigin -> ModuleOrigin # stimes :: Integral b => b -> ModuleOrigin -> ModuleOrigin # | |
| Semigroup UnitVisibility | |
| Semigroup Ordering | Since: base-4.9.0.0 |
| Semigroup OsString | |
| Semigroup PosixString | |
Defined in System.OsString.Internal.Types Methods (<>) :: PosixString -> PosixString -> PosixString # sconcat :: NonEmpty PosixString -> PosixString # stimes :: Integral b => b -> PosixString -> PosixString # | |
| Semigroup WindowsString | |
Defined in System.OsString.Internal.Types Methods (<>) :: WindowsString -> WindowsString -> WindowsString # sconcat :: NonEmpty WindowsString -> WindowsString # stimes :: Integral b => b -> WindowsString -> WindowsString # | |
| Semigroup Doc | |
| Semigroup () | Since: base-4.9.0.0 |
| Semigroup (FromMaybe b) | |
| Semigroup a => Semigroup (JoinWith a) | |
| Semigroup (NonEmptyDList a) | |
| Semigroup (Comparison a) |
(<>) :: Comparison a -> Comparison a -> Comparison a Comparison cmp <> Comparison cmp' = Comparison a a' -> cmp a a' <> cmp a a' |
Defined in Data.Functor.Contravariant Methods (<>) :: Comparison a -> Comparison a -> Comparison a # sconcat :: NonEmpty (Comparison a) -> Comparison a # stimes :: Integral b => b -> Comparison a -> Comparison a # | |
| Semigroup (Equivalence a) |
(<>) :: Equivalence a -> Equivalence a -> Equivalence a Equivalence equiv <> Equivalence equiv' = Equivalence a b -> equiv a b && equiv' a b |
Defined in Data.Functor.Contravariant Methods (<>) :: Equivalence a -> Equivalence a -> Equivalence a # sconcat :: NonEmpty (Equivalence a) -> Equivalence a # stimes :: Integral b => b -> Equivalence a -> Equivalence a # | |
| Semigroup (Predicate a) |
(<>) :: Predicate a -> Predicate a -> Predicate a Predicate pred <> Predicate pred' = Predicate a -> pred a && pred' a |
| Semigroup 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 |
| Ord a => Semigroup (Max a) | Since: base-4.9.0.0 |
| Ord a => Semigroup (Min a) | Since: base-4.9.0.0 |
| Monoid m => Semigroup (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup Methods (<>) :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # sconcat :: NonEmpty (WrappedMonoid m) -> WrappedMonoid m # stimes :: Integral b => b -> WrappedMonoid m -> WrappedMonoid m # | |
| Semigroup (NonEmpty a) | Since: base-4.9.0.0 |
| (Generic a, Semigroup (Rep a ())) => Semigroup (Generically a) | Since: base-4.17.0.0 |
Defined in GHC.Generics Methods (<>) :: Generically a -> Generically a -> Generically a # sconcat :: NonEmpty (Generically a) -> Generically a # stimes :: Integral b => b -> Generically a -> Generically a # | |
| Semigroup p => Semigroup (Par1 p) | Since: base-4.12.0.0 |
| Semigroup (IntMap a) | Since: containers-0.5.7 |
| Semigroup (Seq a) | Since: containers-0.5.7 |
| Ord a => Semigroup (Intersection a) | |
Defined in Data.Set.Internal Methods (<>) :: Intersection a -> Intersection a -> Intersection a # sconcat :: NonEmpty (Intersection a) -> Intersection a # stimes :: Integral b => b -> Intersection a -> Intersection a # | |
| Semigroup (MergeSet a) | |
| Ord a => Semigroup (Set a) | Since: containers-0.5.7 |
| Semigroup (FromMaybe b) | |
| Semigroup (Bag a) | |
| Semigroup (Messages e) | |
| 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 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) | |
| Semigroup b => Semigroup (Fold1 a b) | |
| Semigroup (UniqMap k a) | |
| 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 Methods (<>) :: 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 a, Semigroup b) => Semigroup (a, b) | Since: base-4.9.0.0 |
| Semigroup b => Semigroup (a -> b) | 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 (Constant a b) | |
| (Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c) | Since: base-4.9.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 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)<>zSemigrouplaw)- Concatenation
mconcat=foldr(<>)mempty
You can alternatively define mconcat instead of mempty, in which case the
laws are:
- Unit
mconcat(purex) = x- Multiplication
mconcat(joinxss) =mconcat(fmapmconcatxss)- Subclass
mconcat(toListxs) =sconcatxs
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtypes and make those instances
of Monoid, e.g. Sum and Product.
NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
Instances
| Monoid ByteString | |
Defined in Data.ByteString.Internal.Type Methods mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
| Monoid ByteString | |
Defined in Data.ByteString.Lazy.Internal Methods mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
| Monoid ShortByteString | |
Defined in Data.ByteString.Short.Internal Methods mappend :: ShortByteString -> ShortByteString -> ShortByteString # mconcat :: [ShortByteString] -> ShortByteString # | |
| Monoid IntSet | |
| Monoid OsString | "String-Concatenation" for |
| Monoid PosixString | |
Defined in System.OsString.Internal.Types Methods mempty :: PosixString # mappend :: PosixString -> PosixString -> PosixString # mconcat :: [PosixString] -> PosixString # | |
| Monoid WindowsString | |
Defined in System.OsString.Internal.Types Methods mempty :: WindowsString # mappend :: WindowsString -> WindowsString -> WindowsString # mconcat :: [WindowsString] -> WindowsString # | |
| Monoid UniqueSet | |
| Monoid LabelSet | |
| Monoid FastString | |
Defined in GHC.Data.FastString Methods mempty :: FastString # mappend :: FastString -> FastString -> FastString # mconcat :: [FastString] -> FastString # | |
| Monoid Nablas | |
| Monoid JStat | |
| Monoid CIStatic | |
| Monoid InsideLam | |
| Monoid InterestingCxt | |
Defined in GHC.Types.Basic Methods mappend :: InterestingCxt -> InterestingCxt -> InterestingCxt # mconcat :: [InterestingCxt] -> InterestingCxt # | |
| Monoid ModuleOrigin | |
Defined in GHC.Unit.State Methods mempty :: ModuleOrigin # mappend :: ModuleOrigin -> ModuleOrigin -> ModuleOrigin # mconcat :: [ModuleOrigin] -> ModuleOrigin # | |
| Monoid UnitVisibility | |
| Monoid Ordering | Since: base-2.1 |
| Monoid OsString | "String-Concatenation" for |
| Monoid PosixString | |
Defined in System.OsString.Internal.Types Methods mempty :: PosixString # mappend :: PosixString -> PosixString -> PosixString # mconcat :: [PosixString] -> PosixString # | |
| Monoid WindowsString | |
Defined in System.OsString.Internal.Types Methods mempty :: WindowsString # mappend :: WindowsString -> WindowsString -> WindowsString # mconcat :: [WindowsString] -> WindowsString # | |
| Monoid Doc | |
| Monoid () | Since: base-2.1 |
| Monoid (Comparison a) |
mempty :: Comparison a mempty = Comparison _ _ -> EQ |
Defined in Data.Functor.Contravariant Methods mempty :: Comparison a # mappend :: Comparison a -> Comparison a -> Comparison a # mconcat :: [Comparison a] -> Comparison a # | |
| Monoid (Equivalence a) |
mempty :: Equivalence a mempty = Equivalence _ _ -> True |
Defined in Data.Functor.Contravariant Methods mempty :: Equivalence a # mappend :: Equivalence a -> Equivalence a -> Equivalence a # mconcat :: [Equivalence a] -> Equivalence a # | |
| Monoid (Predicate a) |
mempty :: Predicate a mempty = _ -> True |
| Monoid a => Monoid (Identity a) | Since: base-4.9.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 Methods mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
| (Generic a, Monoid (Rep a ())) => Monoid (Generically a) | Since: base-4.17.0.0 |
Defined in GHC.Generics Methods mempty :: Generically a # mappend :: Generically a -> Generically a -> Generically a # mconcat :: [Generically a] -> Generically a # | |
| Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
| Monoid (IntMap a) | |
| Monoid (Seq a) | |
| Monoid (MergeSet a) | |
| Ord a => Monoid (Set a) | |
| Monoid (Bag a) | |
| Monoid (Messages e) | |
| 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) | |
| Monoid b => Monoid (Fold1 a b) | |
| Monoid (UniqMap k a) | |
| (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 Methods mempty :: Validation e a # mappend :: Validation e a -> Validation e a -> Validation e a # mconcat :: [Validation e a] -> Validation e a # | |
| (Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1 |
| Monoid b => Monoid (a -> b) | Since: base-2.1 |
| Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0 |
| (Semigroup a, Monoid a) => Monoid (Tagged s a) | |
| Monoid a => Monoid (Constant a b) | |
| (Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1 |
| (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 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.Data Methods 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 GHC.Exception.Type Methods toException :: Void -> SomeException # fromException :: SomeException -> Maybe Void # displayException :: Void -> String # | |
| Generic Void | |
| Read Void | Reading a Since: base-4.8.0.0 |
| Show Void | Since: base-4.8.0.0 |
| Eq Void | Since: base-4.8.0.0 |
| Ord Void | Since: base-4.8.0.0 |
| Hashable Void | |
Defined in Data.Hashable.Class | |
| OutputableP env Void | |
Defined in GHC.Utils.Outputable | |
| 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
Constructors
| Identity | |
Fields
| |
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 Methods 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 # | |
| Foldable1 Identity | Since: base-4.18.0.0 |
Defined in Data.Foldable1 Methods 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 # | |
| 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 |
| Hashable1 Identity | |
Defined in Data.Hashable.Class | |
| Traversable1 Identity | |
| Generic1 Identity | |
| Data a => Data (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Data Methods 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 Methods alignment :: Identity a -> Int # peekElemOff :: Ptr (Identity a) -> Int -> IO (Identity a) # pokeElemOff :: Ptr (Identity a) -> Int -> Identity a -> IO () # peekByteOff :: Ptr b -> Int -> IO (Identity a) # pokeByteOff :: Ptr b -> Int -> Identity a -> IO () # | |
| 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 Methods (.&.) :: 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 Methods 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 Methods succ :: Identity a -> Identity a # pred :: Identity a -> Identity a # fromEnum :: Identity a -> Int # enumFrom :: Identity a -> [Identity a] # enumFromThen :: Identity a -> Identity a -> [Identity a] # enumFromTo :: Identity a -> Identity a -> [Identity a] # enumFromThenTo :: Identity a -> Identity a -> Identity a -> [Identity a] # | |
| Floating a => Floating (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity Methods 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 Methods 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 Methods 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 Methods quot :: Identity a -> Identity a -> Identity a # rem :: Identity a -> Identity a -> Identity a # div :: Identity a -> Identity a -> Identity a # mod :: Identity a -> Identity a -> Identity a # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) # divMod :: Identity a -> Identity a -> (Identity a, Identity a) # | |
| Real a => Real (Identity a) | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity Methods 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 |
Defined in Data.Functor.Identity | |
| 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 Methods 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 |
| 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 Methods toRational :: Natural -> Rational # | |
| Show Natural | Since: base-4.8.0.0 |
| Eq Natural | |
| Ord Natural | |
| Hashable Natural | |
Defined in Data.Hashable.Class | |
| UniformRange Natural | |
Defined in System.Random.Internal | |
| 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.Reals
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 Methods 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 Methods (+) :: 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 Methods readsPrec :: Int -> ReadS Scientific # readList :: ReadS [Scientific] # readPrec :: ReadPrec Scientific # readListPrec :: ReadPrec [Scientific] # | |
| Fractional Scientific | WARNING: These methods also compute
|
Defined in Data.Scientific Methods (/) :: Scientific -> Scientific -> Scientific # recip :: Scientific -> Scientific # fromRational :: Rational -> Scientific # | |
| Real Scientific | WARNING: Avoid applying |
Defined in Data.Scientific Methods toRational :: Scientific -> Rational # | |
| RealFrac Scientific | WARNING: the methods of the |
Defined in Data.Scientific Methods 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 Methods 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 Methods rnf :: Scientific -> () # | |
| Eq Scientific | Scientific numbers can be safely compared for equality. No magnitude |
Defined in Data.Scientific | |
| Ord Scientific | Scientific numbers can be safely compared for ordering. No magnitude |
Defined in Data.Scientific Methods 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 | |
| Lift Scientific | Since: scientific-0.3.7.0 |
Defined in Data.Scientific Methods 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.
Minimal complete definition
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:
dimapidid≡id
If you supply lmap and rmap, ensure:
lmapid≡idrmapid≡id
If you supply both, you should also ensure:
dimapf g ≡lmapf.rmapg
These ensure by parametricity:
dimap(f.g) (h.i) ≡dimapg h.dimapf ilmap(f.g) ≡lmapg.lmapfrmap(f.g) ≡rmapf.rmapg
Instances
| Profunctor Fold1 | |
Defined in Control.Foldl.NonEmpty Methods dimap :: (a -> b) -> (c -> d) -> Fold1 b c -> Fold1 a d # lmap :: (a -> b) -> Fold1 b c -> Fold1 a c # rmap :: (b -> c) -> Fold1 a b -> Fold1 a c # (#.) :: forall a b c q. Coercible c b => q b c -> Fold1 a b -> Fold1 a c # (.#) :: forall a b c q. Coercible b a => Fold1 b c -> q a b -> Fold1 a c # | |
| Monad m => Profunctor (Kleisli m) | |
Defined in Data.Profunctor.Unsafe Methods 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 Methods 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 Methods 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 Methods 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 Methods 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 Methods 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 Methods 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 Methods 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 Methods 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) #
Minimal complete definition
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) | |
| 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) | |
| 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 Methods 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) | Since: base-3.0 |
| (Applicative f, Monad f) => Category (WhenMissing f :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods 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 |
| (Monad f, Applicative f) => Category (WhenMatched f x :: Type -> Type -> Type) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods 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 Methods 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) | Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods 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 Methods 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