| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Unison.Prelude
Synopsis
- data Int
- data Word
- class a ~R# b => Coercible (a :: k) (b :: k)
- class Applicative m => Monad (m :: Type -> Type) where
- class Functor (f :: Type -> Type) where
- class Generic1 (f :: k -> Type)
- data Either a b
- data Void
- class Functor f => Applicative (f :: Type -> Type) where
- class Generic a
- data Word8
- data Word64
- data Word32
- data Word16
- class (forall a. Functor (p a)) => Bifunctor (p :: Type -> Type -> Type) where
- class IsString a where
- fromString :: String -> a
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- data Int8
- data Int16
- data Int32
- data Int64
- class (Typeable e, Show e) => Exception e
- class Monad m => MonadIO (m :: Type -> Type) where
- data IOException
- class Typeable (a :: k)
- class Monad m => MonadFail (m :: Type -> Type) where
- data Text
- type HasCallStack = ?callStack :: CallStack
- data SomeException
- class Applicative f => Alternative (f :: Type -> Type) where
- newtype Const a (b :: k) = Const {
- getConst :: a
- newtype Identity a = Identity {
- runIdentity :: a
- newtype ZipList a = ZipList {
- getZipList :: [a]
- newtype WrappedArrow (a :: Type -> Type -> Type) b c = WrapArrow {
- unwrapArrow :: a b c
- newtype WrappedMonad (m :: Type -> Type) a = WrapMonad {
- unwrapMonad :: m a
- data ByteString
- data Map k a
- data Set a
- data Seq a
- newtype MaybeT (m :: Type -> Type) a = MaybeT {}
- class (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) where
- class MonadIO m => MonadUnliftIO (m :: Type -> Type) where
- withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b
- class From source target where
- from :: source -> target
- data TryFromException source target = TryFromException source (Maybe SomeException)
- class TryFrom source target where
- tryFrom :: source -> Either (TryFromException source target) target
- either :: (a -> c) -> (b -> c) -> Either a b -> c
- void :: Functor f => f a -> f ()
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- join :: Monad m => m (m a) -> m a
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- readMaybe :: Read a => String -> Maybe a
- coerce :: forall {k :: RuntimeRep} (a :: TYPE k) (b :: TYPE k). Coercible a b => a -> b
- for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- forever :: Applicative f => f a -> f b
- try :: (MonadUnliftIO m, Exception e) => m a -> m (Either e a)
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- trace :: String -> a -> a
- (>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c
- guard :: Alternative f => Bool -> f ()
- toList :: Foldable t => t a -> [a]
- foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b
- fold :: (Foldable t, Monoid m) => t m -> m
- (<**>) :: Applicative f => f a -> f (a -> b) -> f b
- liftA :: Applicative f => (a -> b) -> f a -> f b
- liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- when :: Applicative f => Bool -> f () -> f ()
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- ap :: Monad m => m (a -> b) -> m a -> m b
- isJust :: Maybe a -> Bool
- isNothing :: Maybe a -> Bool
- fromMaybe :: a -> Maybe a -> a
- maybeToList :: Maybe a -> [a]
- listToMaybe :: [a] -> Maybe a
- catMaybes :: [Maybe a] -> [a]
- mapMaybe :: Filterable f => (a -> Maybe b) -> f a -> f b
- foldl1' :: HasCallStack => (a -> a -> a) -> [a] -> a
- byteSwap16 :: Word16 -> Word16
- byteSwap32 :: Word32 -> Word32
- byteSwap64 :: Word64 -> Word64
- bitReverse8 :: Word8 -> Word8
- bitReverse16 :: Word16 -> Word16
- bitReverse32 :: Word32 -> Word32
- bitReverse64 :: Word64 -> Word64
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- ($>) :: Functor f => f a -> b -> f b
- (&) :: a -> (a -> b) -> b
- optional :: Alternative f => f a -> f (Maybe a)
- lefts :: [Either a b] -> [a]
- rights :: [Either a b] -> [b]
- partitionEithers :: [Either a b] -> ([a], [b])
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b
- traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
- for_ :: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- asum :: (Foldable t, Alternative f) => t (f a) -> f a
- msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
- traceIO :: String -> IO ()
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- replicateM :: Applicative m => Int -> m a -> m [a]
- replicateM_ :: Applicative m => Int -> m a -> m ()
- unless :: Applicative f => Bool -> f () -> f ()
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- traceMarkerIO :: String -> IO ()
- traceMarker :: String -> a -> a
- traceEventIO :: String -> IO ()
- traceEvent :: String -> a -> a
- traceStack :: String -> a -> a
- traceShowM :: (Show a, Applicative f) => a -> f ()
- traceM :: Applicative f => String -> f ()
- traceShowId :: Show a => a -> a
- traceShow :: Show a => a -> b -> b
- traceId :: String -> String
- putTraceMsg :: String -> IO ()
- traceWith :: (a -> String) -> a -> a
- traceShowWith :: Show b => (a -> b) -> a -> a
- traceEventWith :: (a -> String) -> a -> a
- flushEventLog :: IO ()
- mapLeft :: (a -> c) -> Either a b -> Either c b
- maybeToRight :: b -> Maybe a -> Either b a
- mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b]
- whenM :: Monad m => m Bool -> m () -> m ()
- unlessM :: Monad m => m Bool -> m () -> m ()
- ifM :: Monad m => m Bool -> m a -> m a -> m a
- headMay :: [a] -> Maybe a
- lastMay :: [a] -> Maybe a
- atMay :: [a] -> Int -> Maybe a
- readMay :: Read a => String -> Maybe a
- encodeUtf8 :: Text -> ByteString
- decodeUtf8 :: ByteString -> Text
- askUnliftIO :: MonadUnliftIO m => m (UnliftIO m)
- askRunInIO :: MonadUnliftIO m => m (m a -> IO a)
- withUnliftIO :: MonadUnliftIO m => (UnliftIO m -> IO a) -> m a
- into :: forall target source. From source target => source -> target
- tryInto :: forall target source. TryFrom source target => source -> Either (TryFromException source target) target
- wither :: (Witherable t, Applicative f) => (a -> f (Maybe b)) -> t a -> f (t b)
- filterA :: (Witherable t, Applicative f) => (a -> f Bool) -> t a -> f (t a)
- witherMap :: (Witherable t, Applicative m) => (t b -> r) -> (a -> m (Maybe b)) -> t a -> m r
- forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b)
- readUtf8 :: FilePath -> IO Text
- safeReadUtf8 :: FilePath -> IO (Either IOException Text)
- safeReadUtf8StdIn :: IO (Either IOException Text)
- writeUtf8 :: FilePath -> Text -> IO ()
- prependUtf8 :: FilePath -> Text -> IO ()
- uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e
- reportBug :: String -> String -> String
- tShow :: Show a => a -> Text
- wundefined :: HasCallStack => a
- onFalse :: Applicative m => m () -> Bool -> m ()
- onFalseM :: Monad m => m () -> m Bool -> m ()
- onTrue :: Applicative m => m () -> Bool -> m ()
- onTrueM :: Monad m => m () -> m Bool -> m ()
- onNothing :: Applicative m => m a -> Maybe a -> m a
- onNothingM :: Monad m => m a -> m (Maybe a) -> m a
- whenNothing :: Applicative m => Maybe a -> m a -> m a
- whenNothingM :: Monad m => m (Maybe a) -> m a -> m a
- whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m ()
- whenJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m ()
- eitherToMaybe :: Either a b -> Maybe b
- maybeToEither :: a -> Maybe b -> Either a b
- eitherToThese :: Either a b -> These a b
- altSum :: (Alternative f, Foldable t) => t (f a) -> f a
- altMap :: (Alternative f, Foldable t) => (a -> f b) -> t a -> f b
- hoistMaybe :: Applicative m => Maybe a -> MaybeT m a
- onLeft :: Applicative m => (a -> m b) -> Either a b -> m b
- onLeftM :: Monad m => (a -> m b) -> m (Either a b) -> m b
- whenLeft :: Applicative m => Either a b -> (a -> m b) -> m b
- whenLeftM :: Monad m => m (Either a b) -> (a -> m b) -> m b
- throwEitherM :: forall e m a. (MonadIO m, Exception e) => m (Either e a) -> m a
- throwEitherMWith :: forall e e' m a. (MonadIO m, Exception e') => (e -> e') -> m (Either e a) -> m a
- throwExceptT :: (MonadIO m, Exception e) => ExceptT e m a -> m a
- throwExceptTWith :: (MonadIO m, Exception e') => (e -> e') -> ExceptT e m a -> m a
- (^.) :: s -> Getting a s a -> a
- (.~) :: ASetter s t a b -> b -> s -> t
- (%~) :: ASetter s t a b -> (a -> b) -> s -> t
- view :: MonadReader s m => Getting a s a -> m a
- set :: ASetter s t a b -> b -> s -> t
- over :: ASetter s t a b -> (a -> b) -> s -> t
Documentation
A fixed-precision integer type with at least the range [-2^29 .. 2^29-1].
The exact range for a given implementation can be determined by using
minBound and maxBound from the Bounded class.
Instances
Instances
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
class Applicative m => Monad (m :: Type -> Type) where #
The Monad class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do expressions provide a convenient syntax for writing
monadic expressions.
Instances of Monad should satisfy the following:
- Left identity
returna>>=k = k a- Right identity
m>>=return= m- Associativity
m>>=(\x -> k x>>=h) = (m>>=k)>>=h
Furthermore, the Monad and Applicative operations should relate as follows:
The above laws imply:
and that pure and (<*>) satisfy the applicative functor laws.
The instances of Monad for lists, Maybe and IO
defined in the Prelude satisfy these laws.
Minimal complete definition
Methods
(>>=) :: m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
'as ' can be understood as the >>= bsdo expression
do a <- as bs a
(>>) :: m a -> m b -> m b infixl 1 #
Sequentially compose two actions, discarding any value produced by the first, like sequencing operators (such as the semicolon) in imperative languages.
'as ' can be understood as the >> bsdo expression
do as bs
Inject a value into the monadic type.
Instances
| Monad Identity | Since: base-4.8.0.0 |
| Monad NonEmpty | Since: base-4.9.0.0 |
| Monad Par1 | Since: base-4.9.0.0 |
| Monad P | Since: base-2.1 |
| Monad ReadP | Since: base-2.1 |
| Monad Seq | |
| Monad Tree | |
| Monad IO | Since: base-2.1 |
| Monad Array | |
| Monad SmallArray | |
Defined in Data.Primitive.SmallArray Methods (>>=) :: SmallArray a -> (a -> SmallArray b) -> SmallArray b # (>>) :: SmallArray a -> SmallArray b -> SmallArray b # return :: a -> SmallArray a # | |
| Monad Q | |
| Monad Vector | |
| Monad Maybe | Since: base-2.1 |
| Monad Solo | Since: base-4.15 |
| Monad List | Since: base-2.1 |
| Representable f => Monad (Co f) | |
| Monad m => Monad (WrappedMonad m) | Since: base-4.7.0.0 |
Defined in Control.Applicative Methods (>>=) :: WrappedMonad m a -> (a -> WrappedMonad m b) -> WrappedMonad m b # (>>) :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m b # return :: a -> WrappedMonad m a # | |
| ArrowApply a => Monad (ArrowMonad a) | Since: base-2.1 |
Defined in Control.Arrow Methods (>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b # (>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b # return :: a0 -> ArrowMonad a a0 # | |
| Monad (Either e) | Since: base-4.4.0.0 |
| Monad (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Alternative f => Monad (Cofree f) | |
| Functor f => Monad (Free f) | |
| Monad m => Monad (Yoneda m) | |
| Monad (ReifiedFold s) | |
Defined in Control.Lens.Reified Methods (>>=) :: ReifiedFold s a -> (a -> ReifiedFold s b) -> ReifiedFold s b # (>>) :: ReifiedFold s a -> ReifiedFold s b -> ReifiedFold s b # return :: a -> ReifiedFold s a # | |
| Monad (ReifiedGetter s) | |
Defined in Control.Lens.Reified Methods (>>=) :: ReifiedGetter s a -> (a -> ReifiedGetter s b) -> ReifiedGetter s b # (>>) :: ReifiedGetter s a -> ReifiedGetter s b -> ReifiedGetter s b # return :: a -> ReifiedGetter s a # | |
| Semigroup a => Monad (These a) | |
| Semigroup a => Monad (These a) | |
| Monad m => Monad (MaybeT m) | |
| Monoid a => Monad ((,) a) | Since: base-4.9.0.0 |
| Monad m => Monad (Kleisli m a) | Since: base-4.14.0.0 |
| Monad f => Monad (Rec1 f) | Since: base-4.9.0.0 |
| (Applicative f, Monad f) => Monad (WhenMissing f x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods (>>=) :: WhenMissing f x a -> (a -> WhenMissing f x b) -> WhenMissing f x b # (>>) :: WhenMissing f x a -> WhenMissing f x b -> WhenMissing f x b # return :: a -> WhenMissing f x a # | |
| (Alternative f, Monad w) => Monad (CofreeT f w) | |
| (Functor f, Monad m) => Monad (FreeT f m) | |
| Monad (Indexed i a) | |
| (Monad (Rep p), Representable p) => Monad (Prep p) | |
| Monad (Tagged s) | |
| (Monoid w, Functor m, Monad m) => Monad (AccumT w m) | |
| Monad m => Monad (ExceptT e m) | |
| Monad m => Monad (IdentityT m) | |
| Monad m => Monad (ReaderT r m) | |
| Monad m => Monad (SelectT r m) | |
| Monad m => Monad (StateT s m) | |
| Monad m => Monad (StateT s m) | |
| Monad m => Monad (WriterT w m) | |
| (Monoid w, Monad m) => Monad (WriterT w m) | |
| (Monoid w, Monad m) => Monad (WriterT w m) | |
| Monad m => Monad (Reverse m) | Derived instance. |
| (Monoid a, Monoid b) => Monad ((,,) a b) | Since: base-4.14.0.0 |
| (Monad f, Monad g) => Monad (f :*: g) | Since: base-4.9.0.0 |
| Monad (Cokleisli w a) | |
| (Monad f, Applicative f) => Monad (WhenMatched f x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods (>>=) :: WhenMatched f x y a -> (a -> WhenMatched f x y b) -> WhenMatched f x y b # (>>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b # return :: a -> WhenMatched f x y a # | |
| (Applicative f, Monad f) => Monad (WhenMissing f k x) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods (>>=) :: WhenMissing f k x a -> (a -> WhenMissing f k x b) -> WhenMissing f k x b # (>>) :: WhenMissing f k x a -> WhenMissing f k x b -> WhenMissing f k x b # return :: a -> WhenMissing f k x a # | |
| Monad (ContT r m) | |
| (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | Since: base-4.14.0.0 |
| Monad ((->) r) | Since: base-2.1 |
| Monad f => Monad (M1 i c f) | Since: base-4.9.0.0 |
| (Monad f, Applicative f) => Monad (WhenMatched f k x y) | Equivalent to Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods (>>=) :: WhenMatched f k x y a -> (a -> WhenMatched f k x y b) -> WhenMatched f k x y b # (>>) :: WhenMatched f k x y a -> WhenMatched f k x y b -> WhenMatched f k x y b # return :: a -> WhenMatched f k x y a # | |
| Monad m => Monad (RWST r w s m) | |
| (Monoid w, Monad m) => Monad (RWST r w s m) | |
| (Monoid w, Monad m) => Monad (RWST r w s m) | |
class Functor (f :: Type -> Type) where #
A type f is a Functor if it provides a function fmap which, given any types a and b
lets you apply any function from (a -> b) to turn an f a into an f b, preserving the
structure of f. Furthermore f needs to adhere to the following:
Note, that the second law follows from the free theorem of the type fmap and
the first law, so you need only check that the former condition holds.
See https://www.schoolofhaskell.com/user/edwardk/snippets/fmap or
https://github.com/quchen/articles/blob/master/second_functor_law.md
for an explanation.
Minimal complete definition
Methods
fmap :: (a -> b) -> f a -> f b #
fmap is used to apply a function of type (a -> b) to a value of type f a,
where f is a functor, to produce a value of type f b.
Note that for any type constructor with more than one parameter (e.g., Either),
only the last type parameter can be modified with fmap (e.g., b in `Either a b`).
Some type constructors with two parameters or more have a instance that allows
both the last and the penultimate parameters to be mapped over.Bifunctor
Examples
Convert from a to a Maybe IntMaybe String
using show:
>>>fmap show NothingNothing>>>fmap show (Just 3)Just "3"
Convert from an to an
Either Int IntEither Int String using show:
>>>fmap show (Left 17)Left 17>>>fmap show (Right 17)Right "17"
Double each element of a list:
>>>fmap (*2) [1,2,3][2,4,6]
Apply even to the second element of a pair:
>>>fmap even (2,2)(2,True)
It may seem surprising that the function is only applied to the last element of the tuple
compared to the list example above which applies it to every element in the list.
To understand, remember that tuples are type constructors with multiple type parameters:
a tuple of 3 elements (a,b,c) can also be written (,,) a b c and its Functor instance
is defined for Functor ((,,) a b) (i.e., only the third parameter is free to be mapped over
with fmap).
It explains why fmap can be used with tuples containing values of different types as in the
following example:
>>>fmap even ("hello", 1.0, 4)("hello",1.0,True)
Instances
| Functor ZipList | Since: base-2.1 |
| Functor Handler | Since: base-4.6.0.0 |
| Functor Identity | Since: base-4.8.0.0 |
| Functor NonEmpty | Since: base-4.9.0.0 |
| Functor Par1 | Since: base-4.9.0.0 |
| Functor P | Since: base-4.8.0.0 |
Defined in Text.ParserCombinators.ReadP | |
| Functor ReadP | Since: base-2.1 |
| Functor IntMap | |
| Functor Digit | |
| Functor Elem | |
| Functor FingerTree | |
Defined in Data.Sequence.Internal Methods fmap :: (a -> b) -> FingerTree a -> FingerTree b # (<$) :: a -> FingerTree b -> FingerTree a # | |
| Functor Node | |
| Functor Seq | |
| Functor ViewL | |
| Functor ViewR | |
| Functor Tree | |
| Functor IO | Since: base-2.1 |
| Functor AnnotDetails | |
Defined in Text.PrettyPrint.Annotated.HughesPJ Methods fmap :: (a -> b) -> AnnotDetails a -> AnnotDetails b # (<$) :: a -> AnnotDetails b -> AnnotDetails a # | |
| Functor Doc | |
| Functor Span | |
| Functor Doc | Alter the document’s annotations. This instance makes |
| Functor FlattenResult | |
Defined in Prettyprinter.Internal | |
| Functor SimpleDocStream | Alter the document’s annotations. This instance makes |
Defined in Prettyprinter.Internal Methods fmap :: (a -> b) -> SimpleDocStream a -> SimpleDocStream b # (<$) :: a -> SimpleDocStream b -> SimpleDocStream a # | |
| Functor Array | |
| Functor SmallArray | |
Defined in Data.Primitive.SmallArray Methods fmap :: (a -> b) -> SmallArray a -> SmallArray b # (<$) :: a -> SmallArray b -> SmallArray a # | |
| Functor Maybe | |
| Functor Q | |
| Functor TyVarBndr | |
| Functor Flat | |
| Functor FlatApp | |
| Functor Vector | |
| Functor BoolPair | |
Defined in Witherable | |
| Functor Maybe | Since: base-2.1 |
| Functor Solo | Since: base-4.15 |
| Functor List | Since: base-2.1 |
| Functor f => Functor (Co f) | |
| Monad m => Functor (WrappedMonad m) | Since: base-2.1 |
Defined in Control.Applicative Methods fmap :: (a -> b) -> WrappedMonad m a -> WrappedMonad m b # (<$) :: a -> WrappedMonad m b -> WrappedMonad m a # | |
| Arrow a => Functor (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow Methods fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b # (<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 # | |
| Functor (Either a) | Since: base-3.0 |
| Functor (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (V1 :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (Map k) | |
| Functor f => Functor (Cofree f) | |
| Functor f => Functor (Free f) | |
| Functor (Yoneda f) | |
| Functor f => Functor (Indexing f) | |
| Functor f => Functor (Indexing64 f) | |
Defined in Control.Lens.Internal.Indexed Methods fmap :: (a -> b) -> Indexing64 f a -> Indexing64 f b # (<$) :: a -> Indexing64 f b -> Indexing64 f a # | |
| Functor (Level i) | |
| Functor f => Functor (First1 f) | |
Defined in Control.Lens.Lens | |
| Functor (ReifiedFold s) | |
Defined in Control.Lens.Reified Methods fmap :: (a -> b) -> ReifiedFold s a -> ReifiedFold s b # (<$) :: a -> ReifiedFold s b -> ReifiedFold s a # | |
| Functor (ReifiedGetter s) | |
Defined in Control.Lens.Reified Methods fmap :: (a -> b) -> ReifiedGetter s a -> ReifiedGetter s b # (<$) :: a -> ReifiedGetter s b -> ReifiedGetter s a # | |
| Functor (Either a) | |
| Functor (These a) | |
| Functor (Pair e) | |
| Functor (These a) | |
| Functor f => Functor (Lift f) | |
| Functor m => Functor (MaybeT m) | |
| Functor m => Functor (Conc m) | |
| Monad m => Functor (Concurrently m) | Since: unliftio-0.1.0.0 |
Defined in UnliftIO.Internals.Async Methods fmap :: (a -> b) -> Concurrently m a -> Concurrently m b # (<$) :: a -> Concurrently m b -> Concurrently m a # | |
| Functor (HashMap k) | |
| Functor f => Functor (WrappedFoldable f) | |
Defined in Witherable Methods fmap :: (a -> b) -> WrappedFoldable f a -> WrappedFoldable f b # (<$) :: a -> WrappedFoldable f b -> WrappedFoldable f a # | |
| Functor ((,) a) | Since: base-2.1 |
| Arrow a => Functor (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
| Functor m => Functor (Kleisli m a) | Since: base-4.14.0.0 |
| Functor (Const m :: Type -> Type) | Since: base-2.1 |
| (Generic1 f, Functor (Rep1 f)) => Functor (Generically1 f) | Since: base-4.17.0.0 |
Defined in GHC.Generics Methods fmap :: (a -> b) -> Generically1 f a -> Generically1 f b # (<$) :: a -> Generically1 f b -> Generically1 f a # | |
| Functor f => Functor (Rec1 f) | Since: base-4.9.0.0 |
| Functor (URec (Ptr ()) :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Char :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Double :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Float :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Int :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (URec Word :: Type -> Type) | Since: base-4.9.0.0 |
| Bifunctor p => Functor (Fix p) | |
| Bifunctor p => Functor (Join p) | |
| (Applicative f, Monad f) => Functor (WhenMissing f x) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods fmap :: (a -> b) -> WhenMissing f x a -> WhenMissing f x b # (<$) :: a -> WhenMissing f x b -> WhenMissing f x a # | |
| Functor f => Functor (CofreeF f a) | |
| (Functor f, Functor w) => Functor (CofreeT f w) | |
| Functor f => Functor (FreeF f a) | |
| (Functor f, Functor m) => Functor (FreeT f m) | |
| Functor f => Functor (Indexing f) | |
| Functor (Day f g) | |
| Functor (Context a b) | |
| Functor (Indexed i a) | |
| Functor (Flows i b) | |
| Functor (Mafic a b) | |
| Functor (ReifiedIndexedFold i s) | |
Defined in Control.Lens.Reified Methods fmap :: (a -> b) -> ReifiedIndexedFold i s a -> ReifiedIndexedFold i s b # (<$) :: a -> ReifiedIndexedFold i s b -> ReifiedIndexedFold i s a # | |
| Functor (ReifiedIndexedGetter i s) | |
Defined in Control.Lens.Reified Methods fmap :: (a -> b) -> ReifiedIndexedGetter i s a -> ReifiedIndexedGetter i s b # (<$) :: a -> ReifiedIndexedGetter i s b -> ReifiedIndexedGetter i s a # | |
| Functor (Holes t m) | |
Defined in Control.Lens.Traversal | |
| Functor (CopastroSum p a) | |
Defined in Data.Profunctor.Choice Methods fmap :: (a0 -> b) -> CopastroSum p a a0 -> CopastroSum p a b # (<$) :: a0 -> CopastroSum p a b -> CopastroSum p a a0 # | |
| Functor (CotambaraSum p a) | |
Defined in Data.Profunctor.Choice Methods fmap :: (a0 -> b) -> CotambaraSum p a a0 -> CotambaraSum p a b # (<$) :: a0 -> CotambaraSum p a b -> CotambaraSum p a a0 # | |
| Functor (PastroSum p a) | |
| Profunctor p => Functor (TambaraSum p a) | |
Defined in Data.Profunctor.Choice Methods fmap :: (a0 -> b) -> TambaraSum p a a0 -> TambaraSum p a b # (<$) :: a0 -> TambaraSum p a b -> TambaraSum p a a0 # | |
| Profunctor p => Functor (Closure p a) | |
| Functor (Environment p a) | |
Defined in Data.Profunctor.Closed Methods fmap :: (a0 -> b) -> Environment p a a0 -> Environment p a b # (<$) :: a0 -> Environment p a b -> Environment p a a0 # | |
| Profunctor p => Functor (Coprep p) | |
| Profunctor p => Functor (Prep p) | |
| Functor (Copastro p a) | |
| Functor (Cotambara p a) | |
| Functor (Pastro p a) | |
| Profunctor p => Functor (Tambara p a) | |
| Functor (Tagged s) | |
| Functor f => Functor (Backwards f) | Derived instance. |
| Functor m => Functor (AccumT w m) | |
| Functor m => Functor (ExceptT e m) | |
| Functor m => Functor (IdentityT m) | |
| Functor m => Functor (ReaderT r m) | |
| Functor m => Functor (SelectT r m) | |
| Functor m => Functor (StateT s m) | |
| Functor m => Functor (StateT s m) | |
| Functor m => Functor (WriterT w m) | |
| Functor m => Functor (WriterT w m) | |
| Functor m => Functor (WriterT w m) | |
| Functor (Constant a :: Type -> Type) | |
| Functor f => Functor (Reverse f) | Derived instance. |
| Functor ((,,) a b) | Since: base-4.14.0.0 |
| (Functor f, Functor g) => Functor (f :*: g) | Since: base-4.9.0.0 |
| (Functor f, Functor g) => Functor (f :+: g) | Since: base-4.9.0.0 |
| Functor (K1 i c :: Type -> Type) | Since: base-4.9.0.0 |
| Functor (Cokleisli w a) | |
| Functor f => Functor (WhenMatched f x y) | Since: containers-0.5.9 |
Defined in Data.IntMap.Internal Methods fmap :: (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b # (<$) :: a -> WhenMatched f x y b -> WhenMatched f x y a # | |
| (Applicative f, Monad f) => Functor (WhenMissing f k x) | Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods fmap :: (a -> b) -> WhenMissing f k x a -> WhenMissing f k x b # (<$) :: a -> WhenMissing f k x b -> WhenMissing f k x a # | |
| Functor (Bazaar p a b) | |
| Functor (Bazaar1 p a b) | |
| Functor (Pretext p a b) | |
| Functor (Exchange a b s) | |
| Functor (Magma i t b) | |
| Functor (Molten i a b) | |
| Functor (ContT r m) | |
| Functor ((,,,) a b c) | Since: base-4.14.0.0 |
| Functor ((->) r) | Since: base-2.1 |
| (Functor f, Functor g) => Functor (f :.: g) | Since: base-4.9.0.0 |
| Functor f => Functor (M1 i c f) | Since: base-4.9.0.0 |
| Functor (Clown f a :: Type -> Type) | |
| Bifunctor p => Functor (Flip p a) | |
| Functor g => Functor (Joker g a) | |
| Bifunctor p => Functor (WrappedBifunctor p a) | |
Defined in Data.Bifunctor.Wrapped Methods fmap :: (a0 -> b) -> WrappedBifunctor p a a0 -> WrappedBifunctor p a b # (<$) :: a0 -> WrappedBifunctor p a b -> WrappedBifunctor p a a0 # | |
| Functor f => Functor (WhenMatched f k x y) | Since: containers-0.5.9 |
Defined in Data.Map.Internal Methods fmap :: (a -> b) -> WhenMatched f k x y a -> WhenMatched f k x y b # (<$) :: a -> WhenMatched f k x y b -> WhenMatched f k x y a # | |
| Functor (BazaarT p g a b) | |
| Functor (BazaarT1 p g a b) | |
| Functor (PretextT p g a b) | |
| Functor (TakingWhile p f a b) | |
Defined in Control.Lens.Internal.Magma Methods fmap :: (a0 -> b0) -> TakingWhile p f a b a0 -> TakingWhile p f a b b0 # (<$) :: a0 -> TakingWhile p f a b b0 -> TakingWhile p f a b a0 # | |
| Reifies s (ReifiedApplicative f) => Functor (ReflectedApplicative f s) | |
Defined in Data.Reflection Methods fmap :: (a -> b) -> ReflectedApplicative f s a -> ReflectedApplicative f s b # (<$) :: a -> ReflectedApplicative f s b -> ReflectedApplicative f s a # | |
| Functor m => Functor (RWST r w s m) | |
| Functor m => Functor (RWST r w s m) | |
| Functor m => Functor (RWST r w s m) | |
| Functor ((,,,,) a b c d) | Since: base-4.18.0.0 |
| (Functor (f a), Functor (g a)) => Functor (Product f g a) | |
| (Functor (f a), Functor (g a)) => Functor (Sum f g a) | |
| Functor ((,,,,,) a b c d e) | Since: base-4.18.0.0 |
| (Functor f, Bifunctor p) => Functor (Tannen f p a) | |
| Profunctor p => Functor (Procompose p q a) | |
Defined in Data.Profunctor.Composition Methods fmap :: (a0 -> b) -> Procompose p q a a0 -> Procompose p q a b # (<$) :: a0 -> Procompose p q a b -> Procompose p q a a0 # | |
| Profunctor p => Functor (Rift p q a) | |
| Functor ((,,,,,,) a b c d e f) | Since: base-4.18.0.0 |
| (Bifunctor p, Functor g) => Functor (Biff p f g a) | |
class Generic1 (f :: k -> Type) #
Representable types of kind * -> * (or kind k -> *, when PolyKinds
is enabled).
This class is derivable in GHC with the DeriveGeneric flag on.
A Generic1 instance must satisfy the following laws:
from1.to1≡idto1.from1≡id
Instances
| Generic1 ZipList | |
| Generic1 Identity | |
| Generic1 Down | |
| Generic1 NonEmpty | |
| Generic1 Par1 | |
| Generic1 Digit | |
| Generic1 Elem | |
| Generic1 FingerTree | |
Defined in Data.Sequence.Internal Associated Types type Rep1 FingerTree :: k -> Type # Methods from1 :: forall (a :: k). FingerTree a -> Rep1 FingerTree a # to1 :: forall (a :: k). Rep1 FingerTree a -> FingerTree a # | |
| Generic1 Node | |
| Generic1 ViewL | |
| Generic1 ViewR | |
| Generic1 Tree | |
| Generic1 Maybe | |
| Generic1 Maybe | |
| Generic1 Solo | |
| Generic1 List | |
| Generic1 (WrappedMonad m :: Type -> Type) | |
Defined in Control.Applicative Associated Types type Rep1 (WrappedMonad m) :: k -> Type # Methods from1 :: forall (a :: k). WrappedMonad m a -> Rep1 (WrappedMonad m) a # to1 :: forall (a :: k). Rep1 (WrappedMonad m) a -> WrappedMonad m a # | |
| Generic1 (Either a :: Type -> Type) | |
| Functor f => Generic1 (Cofree f :: Type -> Type) | |
| Functor f => Generic1 (Free f :: Type -> Type) | |
| Generic1 (Either a :: Type -> Type) | |
| Generic1 (These a :: Type -> Type) | |
| Generic1 (Pair a :: Type -> Type) | |
| Generic1 (These a :: Type -> Type) | |
| Generic1 (Lift f :: Type -> Type) | |
| Functor m => Generic1 (MaybeT m :: Type -> Type) | |
| Generic1 ((,) a :: Type -> Type) | |
| Generic1 (Proxy :: k -> Type) | |
| Generic1 (U1 :: k -> Type) | |
| Generic1 (V1 :: k -> Type) | |
| Generic1 (WrappedArrow a b :: Type -> Type) | |
Defined in Control.Applicative Associated Types type Rep1 (WrappedArrow a b) :: k -> Type # Methods from1 :: forall (a0 :: k). WrappedArrow a b a0 -> Rep1 (WrappedArrow a b) a0 # to1 :: forall (a0 :: k). Rep1 (WrappedArrow a b) a0 -> WrappedArrow a b a0 # | |
| Generic1 (Kleisli m a :: Type -> Type) | |
| Generic1 (CofreeF f a :: Type -> Type) | |
| Generic1 (FreeF f a :: Type -> Type) | |
| Generic1 (Tagged s :: Type -> Type) | |
| Functor m => Generic1 (ExceptT e m :: Type -> Type) | |
| Generic1 (ReaderT r m :: Type -> Type) | |
| Generic1 ((,,) a b :: Type -> Type) | |
| Generic1 (Const a :: k -> Type) | |
| Generic1 (Rec1 f :: k -> Type) | |
| Generic1 (URec (Ptr ()) :: k -> Type) | |
| Generic1 (URec Char :: k -> Type) | |
| Generic1 (URec Double :: k -> Type) | |
| Generic1 (URec Float :: k -> Type) | |
| Generic1 (URec Int :: k -> Type) | |
| Generic1 (URec Word :: k -> Type) | |
| Generic1 (Backwards f :: k -> Type) | |
| Generic1 (IdentityT f :: k -> Type) | |
| Generic1 (Constant a :: k -> Type) | |
| Generic1 (Reverse f :: k -> Type) | |
| Generic1 ((,,,) a b c :: Type -> Type) | |
| Generic1 (f :*: g :: k -> Type) | |
| Generic1 (f :+: g :: k -> Type) | |
| Generic1 (K1 i c :: k -> Type) | |
| Generic1 ((,,,,) a b c d :: Type -> Type) | |
| Functor f => Generic1 (f :.: g :: k -> Type) | |
| Generic1 (M1 i c f :: k -> Type) | |
| Generic1 (Clown f a :: k1 -> Type) | |
| Generic1 (Joker g a :: k1 -> Type) | |
| Generic1 (WrappedBifunctor p a :: k1 -> Type) | |
Defined in Data.Bifunctor.Wrapped Associated Types type Rep1 (WrappedBifunctor p a) :: k -> Type # Methods from1 :: forall (a0 :: k). WrappedBifunctor p a a0 -> Rep1 (WrappedBifunctor p a) a0 # to1 :: forall (a0 :: k). Rep1 (WrappedBifunctor p a) a0 -> WrappedBifunctor p a a0 # | |
| Generic1 ((,,,,,) a b c d e :: Type -> Type) | |
| Generic1 (Product f g a :: k1 -> Type) | |
| Generic1 (Sum p q a :: k1 -> Type) | |
| Generic1 ((,,,,,,) a b c d e f :: Type -> Type) | |
| Functor f => Generic1 (Tannen f p a :: k2 -> Type) | |
| Generic1 ((,,,,,,,) a b c d e f g :: Type -> Type) | |
| Generic1 ((,,,,,,,,) a b c d e f g h :: Type -> Type) | |
Defined in GHC.Generics Associated Types type Rep1 ((,,,,,,,,) a b c d e f g h) :: k -> Type # Methods from1 :: forall (a0 :: k). (a, b, c, d, e, f, g, h, a0) -> Rep1 ((,,,,,,,,) a b c d e f g h) a0 # to1 :: forall (a0 :: k). Rep1 ((,,,,,,,,) a b c d e f g h) a0 -> (a, b, c, d, e, f, g, h, a0) # | |
| Functor (p (f a)) => Generic1 (Biff p f g a :: k3 -> Type) | |
| Generic1 ((,,,,,,,,,) a b c d e f g h i :: Type -> Type) | |
Defined in GHC.Generics Associated Types type Rep1 ((,,,,,,,,,) a b c d e f g h i) :: k -> Type # Methods from1 :: forall (a0 :: k). (a, b, c, d, e, f, g, h, i, a0) -> Rep1 ((,,,,,,,,,) a b c d e f g h i) a0 # to1 :: forall (a0 :: k). Rep1 ((,,,,,,,,,) a b c d e f g h i) a0 -> (a, b, c, d, e, f, g, h, i, a0) # | |
| Generic1 ((,,,,,,,,,,) a b c d e f g h i j :: Type -> Type) | |
Defined in GHC.Generics Associated Types type Rep1 ((,,,,,,,,,,) a b c d e f g h i j) :: k -> Type # Methods from1 :: forall (a0 :: k). (a, b, c, d, e, f, g, h, i, j, a0) -> Rep1 ((,,,,,,,,,,) a b c d e f g h i j) a0 # to1 :: forall (a0 :: k). Rep1 ((,,,,,,,,,,) a b c d e f g h i j) a0 -> (a, b, c, d, e, f, g, h, i, j, a0) # | |
| Generic1 ((,,,,,,,,,,,) a b c d e f g h i j k :: Type -> Type) | |
Defined in GHC.Generics Associated Types type Rep1 ((,,,,,,,,,,,) a b c d e f g h i j k) :: k -> Type # Methods from1 :: forall (a0 :: k0). (a, b, c, d, e, f, g, h, i, j, k, a0) -> Rep1 ((,,,,,,,,,,,) a b c d e f g h i j k) a0 # to1 :: forall (a0 :: k0). Rep1 ((,,,,,,,,,,,) a b c d e f g h i j k) a0 -> (a, b, c, d, e, f, g, h, i, j, k, a0) # | |
| Generic1 ((,,,,,,,,,,,,) a b c d e f g h i j k l :: Type -> Type) | |
Defined in GHC.Generics Associated Types type Rep1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) :: k -> Type # Methods from1 :: forall (a0 :: k0). (a, b, c, d, e, f, g, h, i, j, k, l, a0) -> Rep1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) a0 # to1 :: forall (a0 :: k0). Rep1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) a0 -> (a, b, c, d, e, f, g, h, i, j, k, l, a0) # | |
| Generic1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m :: Type -> Type) | |
Defined in GHC.Generics Associated Types type Rep1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) :: k -> Type # Methods from1 :: forall (a0 :: k0). (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) -> Rep1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) a0 # to1 :: forall (a0 :: k0). Rep1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) a0 -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) # | |
| Generic1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n :: Type -> Type) | |
Defined in GHC.Generics Associated Types type Rep1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) :: k -> Type # Methods from1 :: forall (a0 :: k0). (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) -> Rep1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) a0 # to1 :: forall (a0 :: k0). Rep1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) a0 -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) # | |
The Either type represents values with two possibilities: a value of
type is either Either a b or Left a.Right b
The Either type is sometimes used to represent a value which is
either correct or an error; by convention, the Left constructor is
used to hold an error value and the Right constructor is used to
hold a correct value (mnemonic: "right" also means "correct").
Examples
The type is the type of values which can be either
a Either String IntString or an Int. The Left constructor can be used only on
Strings, and the Right constructor can be used only on Ints:
>>>let s = Left "foo" :: Either String Int>>>sLeft "foo">>>let n = Right 3 :: Either String Int>>>nRight 3>>>:type ss :: Either String Int>>>:type nn :: Either String Int
The fmap from our Functor instance will ignore Left values, but
will apply the supplied function to values contained in a Right:
>>>let s = Left "foo" :: Either String Int>>>let n = Right 3 :: Either String Int>>>fmap (*2) sLeft "foo">>>fmap (*2) nRight 6
The Monad instance for Either allows us to chain together multiple
actions which may fail, and fail overall if any of the individual
steps failed. First we'll write a function that can either parse an
Int from a Char, or fail.
>>>import Data.Char ( digitToInt, isDigit )>>>:{let parseEither :: Char -> Either String Int parseEither c | isDigit c = Right (digitToInt c) | otherwise = Left "parse error">>>:}
The following should work, since both '1' and '2' can be
parsed as Ints.
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither '1' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleRight 3
But the following should fail overall, since the first operation where
we attempt to parse 'm' as an Int will fail:
>>>:{let parseMultiple :: Either String Int parseMultiple = do x <- parseEither 'm' y <- parseEither '2' return (x + y)>>>:}
>>>parseMultipleLeft "parse error"
Instances
| Bifoldable Either | Since: base-4.10.0.0 |
| Bifunctor Either | Since: base-4.8.0.0 |
| Bitraversable Either | Since: base-4.10.0.0 |
Defined in Data.Bitraversable Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d) # | |
| NFData2 Either | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| Hashable2 Either | |
Defined in Data.Hashable.Class | |
| Bitraversable1 Either | |
Defined in Data.Semigroup.Traversable.Class Methods bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> Either a c -> f (Either b d) # bisequence1 :: Apply f => Either (f a) (f b) -> f (Either a b) # | |
| Generic1 (Either a :: Type -> Type) | |
| (Lift a, Lift b) => Lift (Either a b :: Type) | |
| MonadFix (Either e) | Since: base-4.3.0.0 |
Defined in Control.Monad.Fix | |
| Foldable (Either a) | Since: base-4.7.0.0 |
Defined in Data.Foldable Methods fold :: Monoid m => Either a m -> m # foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # toList :: Either a a0 -> [a0] # length :: Either a a0 -> Int # elem :: Eq a0 => a0 -> Either a a0 -> Bool # maximum :: Ord a0 => Either a a0 -> a0 # minimum :: Ord a0 => Either a a0 -> a0 # | |
| Traversable (Either a) | Since: base-4.7.0.0 |
Defined in Data.Traversable | |
| Applicative (Either e) | Since: base-3.0 |
| Functor (Either a) | Since: base-3.0 |
| Monad (Either e) | Since: base-4.4.0.0 |
| NFData a => NFData1 (Either a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| Hashable a => Hashable1 (Either a) | |
Defined in Data.Hashable.Class | |
| Monoid e => Filterable (Either e) | |
| Monoid e => Witherable (Either e) | |
Defined in Witherable Methods wither :: Applicative f => (a -> f (Maybe b)) -> Either e a -> f (Either e b) # witherM :: Monad m => (a -> m (Maybe b)) -> Either e a -> m (Either e b) # filterA :: Applicative f => (a -> f Bool) -> Either e a -> f (Either e a) # witherMap :: Applicative m => (Either e b -> r) -> (a -> m (Maybe b)) -> Either e a -> m r # | |
| Semigroup (Either a b) | Since: base-4.9.0.0 |
| Generic (Either a b) | |
| (Read a, Read b) => Read (Either a b) | Since: base-3.0 |
| (Show a, Show b) => Show (Either a b) | Since: base-3.0 |
| (NFData a, NFData b) => NFData (Either a b) | |
Defined in Control.DeepSeq | |
| (Eq a, Eq b) => Eq (Either a b) | Since: base-2.1 |
| (Ord a, Ord b) => Ord (Either a b) | Since: base-2.1 |
| (Hashable a, Hashable b) => Hashable (Either a b) | |
Defined in Data.Hashable.Class | |
| (a ~ a', b ~ b') => Each (Either a a') (Either b b') a b |
Since: lens-4.18 |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Product f g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Product f g a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> Product f g a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Product f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Product f g a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (Sum f g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> Sum f g a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> Sum f g a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> Sum f g a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> Sum f g a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :*: g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> (f :*: g) a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :*: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :*: g) a -> b # | |
| (FoldableWithIndex i f, FoldableWithIndex j g) => FoldableWithIndex (Either i j) (f :+: g) | |
Defined in WithIndex Methods ifoldMap :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifoldMap' :: Monoid m => (Either i j -> a -> m) -> (f :+: g) a -> m # ifoldr :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b # ifoldr' :: (Either i j -> a -> b -> b) -> b -> (f :+: g) a -> b # ifoldl' :: (Either i j -> b -> a -> b) -> b -> (f :+: g) a -> b # | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Product f g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (Sum f g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (f :*: g) | |
| (FunctorWithIndex i f, FunctorWithIndex j g) => FunctorWithIndex (Either i j) (f :+: g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Product f g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (Sum f g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :*: g) | |
| (TraversableWithIndex i f, TraversableWithIndex j g) => TraversableWithIndex (Either i j) (f :+: g) | |
| (FilterableWithIndex i f, FilterableWithIndex j g) => FilterableWithIndex (Either i j) (Product f g) | |
| (FilterableWithIndex i f, FilterableWithIndex j g) => FilterableWithIndex (Either i j) (Sum f g) | |
| (WitherableWithIndex i f, WitherableWithIndex j g) => WitherableWithIndex (Either i j) (Product f g) | |
Defined in Witherable Methods iwither :: Applicative f0 => (Either i j -> a -> f0 (Maybe b)) -> Product f g a -> f0 (Product f g b) # iwitherM :: Monad m => (Either i j -> a -> m (Maybe b)) -> Product f g a -> m (Product f g b) # ifilterA :: Applicative f0 => (Either i j -> a -> f0 Bool) -> Product f g a -> f0 (Product f g a) # | |
| (WitherableWithIndex i f, WitherableWithIndex j g) => WitherableWithIndex (Either i j) (Sum f g) | |
Defined in Witherable | |
| type Rep1 (Either a :: Type -> Type) | Since: base-4.6.0.0 |
Defined in GHC.Generics type Rep1 (Either a :: Type -> Type) = D1 ('MetaData "Either" "Data.Either" "base" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1)) | |
| type Rep (Either a b) | Since: base-4.6.0.0 |
Defined in GHC.Generics type Rep (Either a b) = D1 ('MetaData "Either" "Data.Either" "base" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b))) | |
Uninhabited data type
Since: base-4.8.0.0
Instances
class Functor f => Applicative (f :: Type -> Type) where #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*> or liftA2. If it defines both, then they must behave
the same as their default definitions:
(<*>) =liftA2id
liftA2f x y = f<$>x<*>y
Further, any definition must satisfy the following:
- Identity
pureid<*>v = v- Composition
pure(.)<*>u<*>v<*>w = u<*>(v<*>w)- Homomorphism
puref<*>purex =pure(f x)- Interchange
u
<*>purey =pure($y)<*>u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor instance for f will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2p (liftA2q u v) =liftA2f u .liftA2g v
If f is also a Monad, it should satisfy
(which implies that pure and <*> satisfy the applicative functor laws).
Methods
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*> that is more
efficient than the default one.
Example
Used in combination with (, <$>)( can be used to build a record.<*>)
>>>data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
>>>produceFoo :: Applicative f => f Foo
>>>produceBar :: Applicative f => f Bar>>>produceBaz :: Applicative f => f Baz
>>>mkState :: Applicative f => f MyState>>>mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2 that is more
efficient than the default one. In particular, if fmap is an
expensive operation, it is likely better to use liftA2 than to
fmap over the structure and then use <*>.
This became a typeclass method in 4.10.0.0. Prior to that, it was
a function defined in terms of <*> and fmap.
Example
>>>liftA2 (,) (Just 3) (Just 5)Just (3,5)
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
Examples
If used in conjunction with the Applicative instance for Maybe,
you can chain Maybe computations, with a possible "early return"
in case of Nothing.
>>>Just 2 *> Just 3Just 3
>>>Nothing *> Just 3Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>>import Data.Char>>>import Text.ParserCombinators.ReadP>>>let p = string "my name is " *> munch1 isAlpha <* eof>>>readP_to_S p "my name is Simon"[("Simon","")]
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
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
8-bit unsigned integer type
Instances
64-bit unsigned integer type
Instances
32-bit unsigned integer type
Instances
16-bit unsigned integer type
Instances
class (forall a. Functor (p a)) => Bifunctor (p :: Type -> Type -> Type) where #
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
Methods
bimap :: (a -> b) -> (c -> d) -> p a c -> p b d #
Map over both arguments at the same time.
bimapf g ≡firstf.secondg
Examples
>>>bimap toUpper (+1) ('j', 3)('J',4)
>>>bimap toUpper (+1) (Left 'j')Left 'J'
>>>bimap toUpper (+1) (Right 3)Right 4
Instances
| Bifunctor Either | Since: base-4.8.0.0 |
| Bifunctor Either | |
| Bifunctor These | |
| Bifunctor Pair | |
| Bifunctor These | |
| 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 |
| Functor f => Bifunctor (CofreeF f) | |
| Functor f => Bifunctor (FreeF f) | |
| 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) | |
IsString is used in combination with the -XOverloadedStrings
language extension to convert the literals to different string types.
For example, if you use the text package, you can say
{-# LANGUAGE OverloadedStrings #-}
myText = "hello world" :: Text
Internally, the extension will convert this to the equivalent of
myText = fromString @Text ("hello world" :: String)
Note: You can use fromString in normal code as well,
but the usual performance/memory efficiency problems with String apply.
Methods
fromString :: String -> a #
Instances
| IsString ByteString | Beware: |
Defined in Data.ByteString.Internal.Type Methods fromString :: String -> ByteString # | |
| IsString ByteString | Beware: |
Defined in Data.ByteString.Lazy.Internal Methods fromString :: String -> ByteString # | |
| IsString ShortByteString | Beware: |
Defined in Data.ByteString.Short.Internal Methods fromString :: String -> ShortByteString # | |
| IsString Doc | |
Defined in Text.PrettyPrint.HughesPJ Methods fromString :: String -> Doc # | |
| IsString a => IsString (Identity a) | Since: base-4.9.0.0 |
Defined in Data.String Methods fromString :: String -> Identity a # | |
| a ~ Char => IsString (Seq a) | Since: containers-0.5.7 |
Defined in Data.Sequence.Internal Methods fromString :: String -> Seq a # | |
| (IsString a, Hashable a) => IsString (Hashed a) | |
Defined in Data.Hashable.Class Methods fromString :: String -> Hashed a # | |
| IsString (Doc a) | |
Defined in Text.PrettyPrint.Annotated.HughesPJ Methods fromString :: String -> Doc a # | |
| IsString (Doc ann) |
This instance uses the |
Defined in Prettyprinter.Internal Methods fromString :: String -> Doc ann # | |
| a ~ Char => IsString [a] |
Since: base-2.1 |
Defined in Data.String Methods fromString :: String -> [a] # | |
| IsString a => IsString (Const a b) | Since: base-4.9.0.0 |
Defined in Data.String Methods fromString :: String -> Const a b # | |
| IsString a => IsString (Tagged s a) | |
Defined in Data.Tagged Methods fromString :: String -> Tagged s a # | |
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Minimal complete definition
Nothing
Methods
The identity of mplus. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>)
Instances
| MonadPlus P | Since: base-2.1 |
Defined in Text.ParserCombinators.ReadP | |
| MonadPlus ReadP | Since: base-2.1 |
| MonadPlus Seq | |
| MonadPlus IO | Takes the first non-throwing Since: base-4.9.0.0 |
| MonadPlus Array | |
| MonadPlus SmallArray | |
Defined in Data.Primitive.SmallArray | |
| MonadPlus Vector | |
| MonadPlus Maybe | Picks the leftmost Since: base-2.1 |
| MonadPlus List | Combines lists by concatenation, starting from the empty list. Since: base-2.1 |
| (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow | |
| MonadPlus (U1 :: Type -> Type) | Since: base-4.9.0.0 |
| MonadPlus v => MonadPlus (Free v) | This violates the MonadPlus laws, handle with care. |
| MonadPlus m => MonadPlus (Yoneda m) | |
| MonadPlus (ReifiedFold s) | |
Defined in Control.Lens.Reified | |
| Monad m => MonadPlus (MaybeT m) | |
| MonadPlus m => MonadPlus (Kleisli m a) | Since: base-4.14.0.0 |
| MonadPlus f => MonadPlus (Rec1 f) | Since: base-4.9.0.0 |
| (Functor f, MonadPlus m) => MonadPlus (FreeT f m) | |
| (Monoid w, Functor m, MonadPlus m) => MonadPlus (AccumT w m) | |
| (Monad m, Monoid e) => MonadPlus (ExceptT e m) | |
| MonadPlus m => MonadPlus (IdentityT m) | |
| MonadPlus m => MonadPlus (ReaderT r m) | |
| MonadPlus m => MonadPlus (SelectT r m) | |
| MonadPlus m => MonadPlus (StateT s m) | |
| MonadPlus m => MonadPlus (StateT s m) | |
| (Functor m, MonadPlus m) => MonadPlus (WriterT w m) | |
| (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) | |
| (Monoid w, MonadPlus m) => MonadPlus (WriterT w m) | |
| MonadPlus m => MonadPlus (Reverse m) | Derived instance. |
| (MonadPlus f, MonadPlus g) => MonadPlus (f :*: g) | Since: base-4.9.0.0 |
| MonadPlus f => MonadPlus (M1 i c f) | Since: base-4.9.0.0 |
| (Functor m, MonadPlus m) => MonadPlus (RWST r w s m) | |
| (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) | |
| (Monoid w, MonadPlus m) => MonadPlus (RWST r w s m) | |
8-bit signed integer type
Instances
16-bit signed integer type
Instances
32-bit signed integer type
Instances
64-bit signed integer type
Instances
class (Typeable e, Show e) => Exception e #
Any type that you wish to throw or catch as an exception must be an
instance of the Exception class. The simplest case is a new exception
type directly below the root:
data MyException = ThisException | ThatException
deriving Show
instance Exception MyExceptionThe default method definitions in the Exception class do what we need
in this case. You can now throw and catch ThisException and
ThatException as exceptions:
*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException))
Caught ThisException
In more complicated examples, you may wish to define a whole hierarchy of exceptions:
---------------------------------------------------------------------
-- Make the root exception type for all the exceptions in a compiler
data SomeCompilerException = forall e . Exception e => SomeCompilerException e
instance Show SomeCompilerException where
show (SomeCompilerException e) = show e
instance Exception SomeCompilerException
compilerExceptionToException :: Exception e => e -> SomeException
compilerExceptionToException = toException . SomeCompilerException
compilerExceptionFromException :: Exception e => SomeException -> Maybe e
compilerExceptionFromException x = do
SomeCompilerException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make a subhierarchy for exceptions in the frontend of the compiler
data SomeFrontendException = forall e . Exception e => SomeFrontendException e
instance Show SomeFrontendException where
show (SomeFrontendException e) = show e
instance Exception SomeFrontendException where
toException = compilerExceptionToException
fromException = compilerExceptionFromException
frontendExceptionToException :: Exception e => e -> SomeException
frontendExceptionToException = toException . SomeFrontendException
frontendExceptionFromException :: Exception e => SomeException -> Maybe e
frontendExceptionFromException x = do
SomeFrontendException a <- fromException x
cast a
---------------------------------------------------------------------
-- Make an exception type for a particular frontend compiler exception
data MismatchedParentheses = MismatchedParentheses
deriving Show
instance Exception MismatchedParentheses where
toException = frontendExceptionToException
fromException = frontendExceptionFromExceptionWe can now catch a MismatchedParentheses exception as
MismatchedParentheses, SomeFrontendException or
SomeCompilerException, but not other types, e.g. IOException:
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException))
*** Exception: MismatchedParentheses
Instances
class Monad m => MonadIO (m :: Type -> Type) where #
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:
Methods
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
Instances
data IOException #
Exceptions that occur in the IO monad.
An IOException records a more specific error type, a descriptive
string and maybe the handle that was used when the error was
flagged.
Instances
| Exception IOException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: IOException -> SomeException # fromException :: SomeException -> Maybe IOException # displayException :: IOException -> String # | |
| Show IOException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods showsPrec :: Int -> IOException -> ShowS # show :: IOException -> String # showList :: [IOException] -> ShowS # | |
| Eq IOException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
The class Typeable allows a concrete representation of a type to
be calculated.
Minimal complete definition
typeRep#
class Monad m => MonadFail (m :: Type -> Type) where #
When a value is bound in do-notation, the pattern on the left
hand side of <- might not match. In this case, this class
provides a function to recover.
A Monad without a MonadFail instance may only be used in conjunction
with pattern that always match, such as newtypes, tuples, data types with
only a single data constructor, and irrefutable patterns (~pat).
Instances of MonadFail should satisfy the following law: fail s should
be a left zero for >>=,
fail s >>= f = fail s
If your Monad is also MonadPlus, a popular definition is
fail _ = mzero
fail s should be an action that runs in the monad itself, not an
exception (except in instances of MonadIO). In particular,
fail should not be implemented in terms of error.
Since: base-4.9.0.0
Instances
A space efficient, packed, unboxed Unicode text type.
Instances
| Hashable Text | |
Defined in Data.Hashable.Class | |
| Ixed Text | |
Defined in Control.Lens.At | |
| AsEmpty Text | |
Defined in Control.Lens.Empty | |
| Reversing Text | |
Defined in Control.Lens.Internal.Iso | |
| Prefixed Text | |
| Suffixed Text | |
| Pretty Text | Automatically converts all newlines to
Note that
Manually use |
Defined in Prettyprinter.Internal | |
| Cons Text Text Char Char | |
| Snoc Text Text Char Char | |
| (a ~ Char, b ~ Char) => Each Text Text a b |
|
| type Item Text | |
| type Index Text | |
Defined in Control.Lens.At | |
| type IxValue Text | |
Defined in Control.Lens.At | |
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
data SomeException #
The SomeException type is the root of the exception type hierarchy.
When an exception of type e is thrown, behind the scenes it is
encapsulated in a SomeException.
Instances
| Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # | |
| Show SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # | |
class Applicative f => Alternative (f :: Type -> Type) where #
A monoid on applicative functors.
If defined, some and many should be the least solutions
of the equations:
Methods
The identity of <|>
(<|>) :: f a -> f a -> f a infixl 3 #
An associative binary operation
One or more.
Zero or more.
Instances
The Const functor.
Instances
| Generic1 (Const a :: k -> Type) | |
| FoldableWithIndex Void (Const e :: Type -> Type) | |
Defined in WithIndex | |
| FunctorWithIndex Void (Const e :: Type -> Type) | |
| TraversableWithIndex Void (Const e :: Type -> Type) | |
| Unbox a => Vector Vector (Const a b) | |
Defined in Data.Vector.Unboxed.Base Methods basicUnsafeFreeze :: Mutable Vector s (Const a b) -> ST s (Vector (Const a b)) # basicUnsafeThaw :: Vector (Const a b) -> ST s (Mutable Vector s (Const a b)) # basicLength :: Vector (Const a b) -> Int # basicUnsafeSlice :: Int -> Int -> Vector (Const a b) -> Vector (Const a b) # basicUnsafeIndexM :: Vector (Const a b) -> Int -> Box (Const a b) # basicUnsafeCopy :: Mutable Vector s (Const a b) -> Vector (Const a b) -> ST s () # | |
| Unbox a => MVector MVector (Const a b) | |
Defined in Data.Vector.Unboxed.Base Methods basicLength :: MVector s (Const a b) -> Int # basicUnsafeSlice :: Int -> Int -> MVector s (Const a b) -> MVector s (Const a b) # basicOverlaps :: MVector s (Const a b) -> MVector s (Const a b) -> Bool # basicUnsafeNew :: Int -> ST s (MVector s (Const a b)) # basicInitialize :: MVector s (Const a b) -> ST s () # basicUnsafeReplicate :: Int -> Const a b -> ST s (MVector s (Const a b)) # basicUnsafeRead :: MVector s (Const a b) -> Int -> ST s (Const a b) # basicUnsafeWrite :: MVector s (Const a b) -> Int -> Const a b -> ST s () # basicClear :: MVector s (Const a b) -> ST s () # basicSet :: MVector s (Const a b) -> Const a b -> ST s () # basicUnsafeCopy :: MVector s (Const a b) -> MVector s (Const a b) -> ST s () # basicUnsafeMove :: MVector s (Const a b) -> MVector s (Const a b) -> ST s () # basicUnsafeGrow :: MVector s (Const a b) -> Int -> ST s (MVector s (Const a b)) # | |
| Bifoldable (Const :: Type -> Type -> Type) | Since: base-4.10.0.0 |
| Bifunctor (Const :: Type -> Type -> Type) | Since: base-4.8.0.0 |
| Bitraversable (Const :: Type -> Type -> Type) | Since: base-4.10.0.0 |
Defined in Data.Bitraversable Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Const a b -> f (Const c d) # | |
| NFData2 (Const :: Type -> Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| Hashable2 (Const :: Type -> Type -> Type) | |
Defined in Data.Hashable.Class | |
| Bitraversable1 (Const :: Type -> Type -> Type) | |
Defined in Data.Semigroup.Traversable.Class Methods bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> Const a c -> f (Const b d) # bisequence1 :: Apply f => Const (f a) (f b) -> f (Const a b) # | |
| Foldable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Functor.Const Methods fold :: Monoid m0 => Const m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> Const m a -> m0 # foldr :: (a -> b -> b) -> b -> Const m a -> b # foldr' :: (a -> b -> b) -> b -> Const m a -> b # foldl :: (b -> a -> b) -> b -> Const m a -> b # foldl' :: (b -> a -> b) -> b -> Const m a -> b # foldr1 :: (a -> a -> a) -> Const m a -> a # foldl1 :: (a -> a -> a) -> Const m a -> a # elem :: Eq a => a -> Const m a -> Bool # maximum :: Ord a => Const m a -> a # minimum :: Ord a => Const m a -> a # | |
| Contravariant (Const a :: Type -> Type) | |
| Traversable (Const m :: Type -> Type) | Since: base-4.7.0.0 |
| Monoid m => Applicative (Const m :: Type -> Type) | Since: base-2.0.1 |
| Functor (Const m :: Type -> Type) | Since: base-2.1 |
| NFData a => NFData1 (Const a :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| Hashable a => Hashable1 (Const a :: Type -> Type) | |
Defined in Data.Hashable.Class | |
| Filterable (Const r :: Type -> Type) | |
| Witherable (Const r :: Type -> Type) | |
Defined in Witherable Methods wither :: Applicative f => (a -> f (Maybe b)) -> Const r a -> f (Const r b) # witherM :: Monad m => (a -> m (Maybe b)) -> Const r a -> m (Const r b) # filterA :: Applicative f => (a -> f Bool) -> Const r a -> f (Const r a) # witherMap :: Applicative m => (Const r b -> r0) -> (a -> m (Maybe b)) -> Const r a -> m r0 # | |
| Sieve (Forget r :: Type -> Type -> Type) (Const r :: Type -> Type) | |
Defined in Data.Profunctor.Sieve | |
| IsString a => IsString (Const a b) | Since: base-4.9.0.0 |
Defined in Data.String Methods fromString :: String -> Const a b # | |
| Storable a => Storable (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
| Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
| Semigroup a => Semigroup (Const a b) | Since: base-4.9.0.0 |
| Bits a => Bits (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods (.&.) :: Const a b -> Const a b -> Const a b # (.|.) :: Const a b -> Const a b -> Const a b # xor :: Const a b -> Const a b -> Const a b # complement :: Const a b -> Const a b # shift :: Const a b -> Int -> Const a b # rotate :: Const a b -> Int -> Const a b # setBit :: Const a b -> Int -> Const a b # clearBit :: Const a b -> Int -> Const a b # complementBit :: Const a b -> Int -> Const a b # testBit :: Const a b -> Int -> Bool # bitSizeMaybe :: Const a b -> Maybe Int # isSigned :: Const a b -> Bool # shiftL :: Const a b -> Int -> Const a b # unsafeShiftL :: Const a b -> Int -> Const a b # shiftR :: Const a b -> Int -> Const a b # unsafeShiftR :: Const a b -> Int -> Const a b # rotateL :: Const a b -> Int -> Const a b # | |
| FiniteBits a => FiniteBits (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods finiteBitSize :: Const a b -> Int # countLeadingZeros :: Const a b -> Int # countTrailingZeros :: Const a b -> Int # | |
| Bounded a => Bounded (Const a b) | Since: base-4.9.0.0 |
| Enum a => Enum (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods succ :: Const a b -> Const a b # pred :: Const a b -> Const a b # fromEnum :: Const a b -> Int # enumFrom :: Const a b -> [Const a b] # enumFromThen :: Const a b -> Const a b -> [Const a b] # enumFromTo :: Const a b -> Const a b -> [Const a b] # enumFromThenTo :: Const a b -> Const a b -> Const a b -> [Const a b] # | |
| Floating a => Floating (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods exp :: Const a b -> Const a b # log :: Const a b -> Const a b # sqrt :: Const a b -> Const a b # (**) :: Const a b -> Const a b -> Const a b # logBase :: Const a b -> Const a b -> Const a b # sin :: Const a b -> Const a b # cos :: Const a b -> Const a b # tan :: Const a b -> Const a b # asin :: Const a b -> Const a b # acos :: Const a b -> Const a b # atan :: Const a b -> Const a b # sinh :: Const a b -> Const a b # cosh :: Const a b -> Const a b # tanh :: Const a b -> Const a b # asinh :: Const a b -> Const a b # acosh :: Const a b -> Const a b # atanh :: Const a b -> Const a b # log1p :: Const a b -> Const a b # expm1 :: Const a b -> Const a b # | |
| RealFloat a => RealFloat (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods floatRadix :: Const a b -> Integer # floatDigits :: Const a b -> Int # floatRange :: Const a b -> (Int, Int) # decodeFloat :: Const a b -> (Integer, Int) # encodeFloat :: Integer -> Int -> Const a b # exponent :: Const a b -> Int # significand :: Const a b -> Const a b # scaleFloat :: Int -> Const a b -> Const a b # isInfinite :: Const a b -> Bool # isDenormalized :: Const a b -> Bool # isNegativeZero :: Const a b -> Bool # | |
| Generic (Const a b) | |
| Ix a => Ix (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods range :: (Const a b, Const a b) -> [Const a b] # index :: (Const a b, Const a b) -> Const a b -> Int # unsafeIndex :: (Const a b, Const a b) -> Const a b -> Int # inRange :: (Const a b, Const a b) -> Const a b -> Bool # rangeSize :: (Const a b, Const a b) -> Int # unsafeRangeSize :: (Const a b, Const a b) -> Int # | |
| Num a => Num (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
| Read a => Read (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| Fractional a => Fractional (Const a b) | Since: base-4.9.0.0 |
| Integral a => Integral (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods quot :: Const a b -> Const a b -> Const a b # rem :: Const a b -> Const a b -> Const a b # div :: Const a b -> Const a b -> Const a b # mod :: Const a b -> Const a b -> Const a b # quotRem :: Const a b -> Const a b -> (Const a b, Const a b) # divMod :: Const a b -> Const a b -> (Const a b, Const a b) # | |
| Real a => Real (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const Methods toRational :: Const a b -> Rational # | |
| RealFrac a => RealFrac (Const a b) | Since: base-4.9.0.0 |
| Show a => Show (Const a b) | This instance would be equivalent to the derived instances of the
Since: base-4.8.0.0 |
| NFData a => NFData (Const a b) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
| Eq a => Eq (Const a b) | Since: base-4.9.0.0 |
| Ord a => Ord (Const a b) | Since: base-4.9.0.0 |
| Hashable a => Hashable (Const a b) | |
Defined in Data.Hashable.Class | |
| Wrapped (Const a x) | |
| Pretty a => Pretty (Const a b) | |
Defined in Prettyprinter.Internal | |
| Unbox a => Unbox (Const a b) | |
Defined in Data.Vector.Unboxed.Base | |
| t ~ Const a' x' => Rewrapped (Const a x) t | |
Defined in Control.Lens.Wrapped | |
| type Rep1 (Const a :: k -> Type) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
| newtype MVector s (Const a b) | |
Defined in Data.Vector.Unboxed.Base | |
| type Rep (Const a b) | Since: base-4.9.0.0 |
Defined in Data.Functor.Const | |
| type Unwrapped (Const a x) | |
Defined in Control.Lens.Wrapped | |
| newtype Vector (Const a b) | |
Defined in Data.Vector.Unboxed.Base | |
Identity functor and monad. (a non-strict monad)
Since: base-4.8.0.0
Constructors
| Identity | |
Fields
| |
Instances
Lists, but with an Applicative functor based on zipping.
Constructors
| ZipList | |
Fields
| |
Instances
| Foldable ZipList | Since: base-4.9.0.0 |
Defined in Control.Applicative Methods fold :: Monoid m => ZipList m -> m # foldMap :: Monoid m => (a -> m) -> ZipList a -> m # foldMap' :: Monoid m => (a -> m) -> ZipList a -> m # foldr :: (a -> b -> b) -> b -> ZipList a -> b # foldr' :: (a -> b -> b) -> b -> ZipList a -> b # foldl :: (b -> a -> b) -> b -> ZipList a -> b # foldl' :: (b -> a -> b) -> b -> ZipList a -> b # foldr1 :: (a -> a -> a) -> ZipList a -> a # foldl1 :: (a -> a -> a) -> ZipList a -> a # elem :: Eq a => a -> ZipList a -> Bool # maximum :: Ord a => ZipList a -> a # minimum :: Ord a => ZipList a -> a # | |
| Traversable ZipList | Since: base-4.9.0.0 |
| Alternative ZipList | Since: base-4.11.0.0 |
| Applicative ZipList | f <$> ZipList xs1 <*> ... <*> ZipList xsN
= ZipList (zipWithN f xs1 ... xsN)where (\a b c -> stimes c [a, b]) <$> ZipList "abcd" <*> ZipList "567" <*> ZipList [1..]
= ZipList (zipWith3 (\a b c -> stimes c [a, b]) "abcd" "567" [1..])
= ZipList {getZipList = ["a5","b6b6","c7c7c7"]}Since: base-2.1 |
| Functor ZipList | Since: base-2.1 |
| NFData1 ZipList | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
| Filterable ZipList | |
| Witherable ZipList | |
Defined in Witherable Methods wither :: Applicative f => (a -> f (Maybe b)) -> ZipList a -> f (ZipList b) # witherM :: Monad m => (a -> m (Maybe b)) -> ZipList a -> m (ZipList b) # filterA :: Applicative f => (a -> f Bool) -> ZipList a -> f (ZipList a) # witherMap :: Applicative m => (ZipList b -> r) -> (a -> m (Maybe b)) -> ZipList a -> m r # | |
| Generic1 ZipList | |
| FoldableWithIndex Int ZipList | |
Defined in WithIndex | |
| FunctorWithIndex Int ZipList | Same instance as for |
| TraversableWithIndex Int ZipList | |
| FilterableWithIndex Int ZipList | |
| WitherableWithIndex Int ZipList | |
| Generic (ZipList a) | |
| IsList (ZipList a) | Since: base-4.15.0.0 |
| Read a => Read (ZipList a) | Since: base-4.7.0.0 |
| Show a => Show (ZipList a) | Since: base-4.7.0.0 |
| NFData a => NFData (ZipList a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
| Eq a => Eq (ZipList a) | Since: base-4.7.0.0 |
| Ord a => Ord (ZipList a) | Since: base-4.7.0.0 |
| AsEmpty (ZipList a) | |
Defined in Control.Lens.Empty | |
| Wrapped (ZipList a) | |
| t ~ ZipList b => Rewrapped (ZipList a) t | |
Defined in Control.Lens.Wrapped | |
| Cons (ZipList a) (ZipList b) a b | |
| Snoc (ZipList a) (ZipList b) a b | |
| type Rep1 ZipList | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
| type Rep (ZipList a) | Since: base-4.7.0.0 |
Defined in Control.Applicative | |
| type Item (ZipList a) | |
Defined in GHC.IsList | |
| type Unwrapped (ZipList a) | |
Defined in Control.Lens.Wrapped | |
newtype WrappedArrow (a :: Type -> Type -> Type) b c #
Constructors
| WrapArrow | |
Fields
| |
Instances
| Generic1 (WrappedArrow a b :: Type -> Type) | |
Defined in Control.Applicative Associated Types type Rep1 (WrappedArrow a b) :: k -> Type # Methods from1 :: forall (a0 :: k). WrappedArrow a b a0 -> Rep1 (WrappedArrow a b) a0 # to1 :: forall (a0 :: k). Rep1 (WrappedArrow a b) a0 -> WrappedArrow a b a0 # | |
| (ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods empty :: WrappedArrow a b a0 # (<|>) :: WrappedArrow a b a0 -> WrappedArrow a b a0 -> WrappedArrow a b a0 # some :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # many :: WrappedArrow a b a0 -> WrappedArrow a b [a0] # | |
| Arrow a => Applicative (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods pure :: a0 -> WrappedArrow a b a0 # (<*>) :: WrappedArrow a b (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # liftA2 :: (a0 -> b0 -> c) -> WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b c # (*>) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b b0 # (<*) :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
| Arrow a => Functor (WrappedArrow a b) | Since: base-2.1 |
Defined in Control.Applicative Methods fmap :: (a0 -> b0) -> WrappedArrow a b a0 -> WrappedArrow a b b0 # (<$) :: a0 -> WrappedArrow a b b0 -> WrappedArrow a b a0 # | |
| Generic (WrappedArrow a b c) | |
Defined in Control.Applicative Associated Types type Rep (WrappedArrow a b c) :: Type -> Type # Methods from :: WrappedArrow a b c -> Rep (WrappedArrow a b c) x # to :: Rep (WrappedArrow a b c) x -> WrappedArrow a b c # | |
| Wrapped (WrappedArrow a b c) | |
Defined in Control.Lens.Wrapped Associated Types type Unwrapped (WrappedArrow a b c) # Methods _Wrapped' :: Iso' (WrappedArrow a b c) (Unwrapped (WrappedArrow a b c)) # | |
| t ~ WrappedArrow a' b' c' => Rewrapped (WrappedArrow a b c) t | |
Defined in Control.Lens.Wrapped | |
| type Rep1 (WrappedArrow a b :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Control.Applicative type Rep1 (WrappedArrow a b :: Type -> Type) = D1 ('MetaData "WrappedArrow" "Control.Applicative" "base" 'True) (C1 ('MetaCons "WrapArrow" 'PrefixI 'True) (S1 ('MetaSel ('Just "unwrapArrow") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 (a b)))) | |
| type Rep (WrappedArrow a b c) | Since: base-4.7.0.0 |
Defined in Control.Applicative type Rep (WrappedArrow a b c) = D1 ('MetaData "WrappedArrow" "Control.Applicative" "base" 'True) (C1 ('MetaCons "WrapArrow" 'PrefixI 'True) (S1 ('MetaSel ('Just "unwrapArrow") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a b c)))) | |
| type Unwrapped (WrappedArrow a b c) | |
Defined in Control.Lens.Wrapped | |
newtype WrappedMonad (m :: Type -> Type) a #
Constructors
| WrapMonad | |
Fields
| |
Instances
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
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 | |
| FoldableWithIndex k (Map k) | |
| FunctorWithIndex k (Map k) | |
| TraversableWithIndex k (Map k) | |
| Ord k => TraverseMax k (Map k) | |
Defined in Control.Lens.Traversal Methods traverseMax :: IndexedTraversal' k (Map k v) v # | |
| Ord k => TraverseMin k (Map k) | |
Defined in Control.Lens.Traversal Methods traverseMin :: IndexedTraversal' k (Map k v) v # | |
| FilterableWithIndex k (Map k) | |
| WitherableWithIndex k (Map k) | |
| (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) | |
| Hashable k => Hashable1 (Map k) | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
| Filterable (Map k) | |
| Witherable (Map k) | |
Defined in Witherable Methods wither :: Applicative f => (a -> f (Maybe b)) -> Map k a -> f (Map k b) # witherM :: Monad m => (a -> m (Maybe b)) -> Map k a -> m (Map k b) # filterA :: Applicative f => (a -> f Bool) -> Map k a -> f (Map k a) # witherMap :: Applicative m => (Map k b -> r) -> (a -> m (Maybe b)) -> Map k a -> m r # | |
| (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 | |
| (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 | |
| Ord k => At (Map k a) | |
| Ord k => Ixed (Map k a) | |
Defined in Control.Lens.At | |
| AsEmpty (Map k a) | |
Defined in Control.Lens.Empty | |
| Ord k => Wrapped (Map k a) | |
| (t ~ Map k' a', Ord k) => Rewrapped (Map k a) t | |
Defined in Control.Lens.Wrapped | |
| c ~ d => Each (Map c a) (Map d b) a b |
|
| type Item (Map k v) | |
Defined in Data.Map.Internal | |
| type Index (Map k a) | |
Defined in Control.Lens.At | |
| type IxValue (Map k a) | |
Defined in Control.Lens.At | |
| type Unwrapped (Map k a) | |
Defined in Control.Lens.Wrapped | |
A set of values a.
Instances
| Foldable Set | Folds in order of increasing key. |
Defined in Data.Set.Internal Methods fold :: Monoid m => Set m -> m # foldMap :: Monoid m => (a -> m) -> Set a -> m # foldMap' :: Monoid m => (a -> m) -> Set a -> m # foldr :: (a -> b -> b) -> b -> Set a -> b # foldr' :: (a -> b -> b) -> b -> Set a -> b # foldl :: (b -> a -> b) -> b -> Set a -> b # foldl' :: (b -> a -> b) -> b -> Set a -> b # foldr1 :: (a -> a -> a) -> Set a -> a # foldl1 :: (a -> a -> a) -> Set a -> a # elem :: Eq a => a -> Set a -> Bool # maximum :: Ord a => Set a -> a # | |
| Eq1 Set | Since: containers-0.5.9 |
| Ord1 Set | Since: containers-0.5.9 |
Defined in Data.Set.Internal | |
| Show1 Set | Since: containers-0.5.9 |
| Hashable1 Set | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
| Lift a => Lift (Set a :: Type) | Since: containers-0.6.6 |
| (Data a, Ord a) => Data (Set a) | |
Defined in Data.Set.Internal Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Set a -> c (Set a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Set a) # dataTypeOf :: Set a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Set a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set a)) # gmapT :: (forall b. Data b => b -> b) -> Set a -> Set a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r # gmapQ :: (forall d. Data d => d -> u) -> Set a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Set a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Set a -> m (Set a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Set a -> m (Set a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Set a -> m (Set a) # | |
| Ord a => Monoid (Set a) | |
| Ord a => Semigroup (Set a) | Since: containers-0.5.7 |
| Ord a => IsList (Set a) | Since: containers-0.5.6.2 |
| (Read a, Ord a) => Read (Set a) | |
| Show a => Show (Set a) | |
| NFData a => NFData (Set a) | |
Defined in Data.Set.Internal | |
| Eq a => Eq (Set a) | |
| Ord a => Ord (Set a) | |
| Hashable v => Hashable (Set v) | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
| Ord k => At (Set k) | |
| Ord a => Contains (Set a) | |
| Ord k => Ixed (Set k) | |
Defined in Control.Lens.At | |
| AsEmpty (Set a) | |
Defined in Control.Lens.Empty | |
| Ord a => Wrapped (Set a) | |
| (t ~ Set a', Ord a) => Rewrapped (Set a) t | |
Defined in Control.Lens.Wrapped | |
| type Item (Set a) | |
Defined in Data.Set.Internal | |
| type Index (Set a) | |
Defined in Control.Lens.At | |
| type IxValue (Set k) | |
Defined in Control.Lens.At | |
| type Unwrapped (Set a) | |
Defined in Control.Lens.Wrapped | |
General-purpose finite sequences.
Instances
| MonadFix Seq | Since: containers-0.5.11 |
Defined in Data.Sequence.Internal | |
| MonadZip Seq |
|
| Foldable Seq | |
Defined in Data.Sequence.Internal Methods fold :: Monoid m => Seq m -> m # foldMap :: Monoid m => (a -> m) -> Seq a -> m # foldMap' :: Monoid m => (a -> m) -> Seq a -> m # foldr :: (a -> b -> b) -> b -> Seq a -> b # foldr' :: (a -> b -> b) -> b -> Seq a -> b # foldl :: (b -> a -> b) -> b -> Seq a -> b # foldl' :: (b -> a -> b) -> b -> Seq a -> b # foldr1 :: (a -> a -> a) -> Seq a -> a # foldl1 :: (a -> a -> a) -> Seq a -> a # elem :: Eq a => a -> Seq a -> Bool # maximum :: Ord a => Seq a -> a # | |
| Eq1 Seq | Since: containers-0.5.9 |
| Ord1 Seq | Since: containers-0.5.9 |
Defined in Data.Sequence.Internal | |
| Read1 Seq | Since: containers-0.5.9 |
Defined in Data.Sequence.Internal | |
| Show1 Seq | Since: containers-0.5.9 |
| Traversable Seq | |
| Alternative Seq | Since: containers-0.5.4 |
| Applicative Seq | Since: containers-0.5.4 |
| Functor Seq | |
| Monad Seq | |
| MonadPlus Seq | |
| UnzipWith Seq | |
Defined in Data.Sequence.Internal Methods unzipWith' :: (x -> (a, b)) -> Seq x -> (Seq a, Seq b) | |
| Hashable1 Seq | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
| Filterable Seq | |
| Witherable Seq | |
Defined in Witherable | |
| FoldableWithIndex Int Seq | |
| FunctorWithIndex Int Seq | The position in the |
| TraversableWithIndex Int Seq | |
| FilterableWithIndex Int Seq | |
| WitherableWithIndex Int Seq | |
| Lift a => Lift (Seq a :: Type) | Since: containers-0.6.6 |
| Data a => Data (Seq a) | |
Defined in Data.Sequence.Internal Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Seq a -> c (Seq a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Seq a) # dataTypeOf :: Seq a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Seq a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Seq a)) # gmapT :: (forall b. Data b => b -> b) -> Seq a -> Seq a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Seq a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Seq a -> r # gmapQ :: (forall d. Data d => d -> u) -> Seq a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Seq a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Seq a -> m (Seq a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Seq a -> m (Seq a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Seq a -> m (Seq a) # | |
| a ~ Char => IsString (Seq a) | Since: containers-0.5.7 |
Defined in Data.Sequence.Internal Methods fromString :: String -> Seq a # | |
| Monoid (Seq a) | |
| Semigroup (Seq a) | Since: containers-0.5.7 |
| IsList (Seq a) | |
| Read a => Read (Seq a) | |
| Show a => Show (Seq a) | |
| NFData a => NFData (Seq a) | |
Defined in Data.Sequence.Internal | |
| Eq a => Eq (Seq a) | |
| Ord a => Ord (Seq a) | |
| Hashable v => Hashable (Seq v) | Since: hashable-1.3.4.0 |
Defined in Data.Hashable.Class | |
| Ixed (Seq a) | |
Defined in Control.Lens.At | |
| AsEmpty (Seq a) | |
Defined in Control.Lens.Empty | |
| Reversing (Seq a) | |
Defined in Control.Lens.Internal.Iso | |
| Wrapped (Seq a) | |
| t ~ Seq a' => Rewrapped (Seq a) t | |
Defined in Control.Lens.Wrapped | |
| Cons (Seq a) (Seq b) a b | |
| Snoc (Seq a) (Seq b) a b | |
| Each (Seq a) (Seq b) a b |
|
| type Item (Seq a) | |
Defined in Data.Sequence.Internal | |
| type Index (Seq a) | |
Defined in Control.Lens.At | |
| type IxValue (Seq a) | |
Defined in Control.Lens.At | |
| type Unwrapped (Seq a) | |
Defined in Control.Lens.Wrapped | |
newtype MaybeT (m :: Type -> Type) a #
The parameterizable maybe monad, obtained by composing an arbitrary
monad with the Maybe monad.
Computations are actions that may produce a value or exit.
The return function yields a computation that produces that
value, while >>= sequences two subcomputations, exiting if either
computation does.
Instances
class (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) where #
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.
Methods
lift :: Monad m => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
Instances
class MonadIO m => MonadUnliftIO (m :: Type -> Type) where #
Monads which allow their actions to be run in IO.
While MonadIO allows an IO action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO to ReaderT and IdentityT transformers on top of
IO.
Laws. For any function run provided by withRunInIO, it must meet the
monad transformer laws as reformulated for MonadUnliftIO:
run . return = return
run (m >>= f) = run m >>= run . f
Instances of MonadUnliftIO must also satisfy the following laws:
- Identity law
withRunInIO (\run -> run m) = m- Inverse law
withRunInIO (\_ -> m) = liftIO m
As an example of an invalid instance, a naive implementation of
MonadUnliftIO (StateT s m) might be
withRunInIO inner =
StateT $ \s ->
withRunInIO $ \run ->
inner (run . flip evalStateT s)
This breaks the identity law because the inner run m would throw away
any state changes in m.
Since: unliftio-core-0.1.0.0
Methods
withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b #
Convenience function for capturing the monadic context and running an IO
action with a runner function. The runner function is used to run a monadic
action m in IO.
Since: unliftio-core-0.1.0.0
Instances
| MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
| MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
| MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift | |
class From source target where #
This type class is for converting values from some source type into
some other target type. The constraint means that
you can convert from a value of type From source targetsource into a value of type
target.
This type class is for conversions that always succeed. If your conversion
sometimes fails, consider implementing TryFrom instead.
Minimal complete definition
Nothing
Methods
This method implements the conversion of a value between types. At call
sites you may prefer to use into instead.
-- Avoid this: from (x :: s) -- Prefer this (using [@TypeApplications@](https://downloads.haskell.org/ghc/9.6.1/docs/users_guide/exts/type_applications.html) language extension): from @s x
The default implementation of this method simply calls coerce,
which works for types that have the same runtime representation. This
means that for newtypes you do not need to implement this method at
all. For example:
>>>newtype Name = Name String>>>instance From Name String>>>instance From String Name
data TryFromException source target #
This exception is thrown when a TryFrom conversion fails. It has the
original source value that caused the failure and it knows the target
type it was trying to convert into. It also has an optional
SomeException for communicating what went wrong while
converting.
Constructors
| TryFromException source (Maybe SomeException) |
Instances
| (Show source, Typeable source, Typeable target) => Exception (TryFromException source target) | |
Defined in Witch.TryFromException Methods toException :: TryFromException source target -> SomeException # fromException :: SomeException -> Maybe (TryFromException source target) # displayException :: TryFromException source target -> String # | |
| (Show source, Typeable source, Typeable target) => Show (TryFromException source target) | |
Defined in Witch.TryFromException Methods showsPrec :: Int -> TryFromException source target -> ShowS # show :: TryFromException source target -> String # showList :: [TryFromException source target] -> ShowS # | |
class TryFrom source target where #
This type class is for converting values from some source type into
some other target type. The constraint means
that you may be able to convert from a value of type TryFrom source targetsource into a value
of type target, but that conversion may fail at runtime.
This type class is for conversions that can sometimes fail. If your
conversion always succeeds, consider implementing From instead.
Methods
tryFrom :: source -> Either (TryFromException source target) target #
This method implements the conversion of a value between types. At call
sites you may want to use tryInto instead.
-- Avoid this: tryFrom (x :: s) -- Prefer this: tryFrom @s
Consider using maybeTryFrom or eitherTryFrom to implement this
method.
either :: (a -> c) -> (b -> c) -> Either a b -> c #
Case analysis for the Either type.
If the value is , apply the first function to Left aa;
if it is , apply the second function to Right bb.
Examples
We create two values of type , one using the
Either String IntLeft constructor and another using the Right constructor. Then
we apply "either" the length function (if we have a String)
or the "times-two" function (if we have an Int):
>>>let s = Left "foo" :: Either String Int>>>let n = Right 3 :: Either String Int>>>either length (*2) s3>>>either length (*2) n6
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing>>>void (Just 3)Just ()
Replace the contents of an
with unit, resulting in an Either Int Int:Either Int ()
>>>void (Left 8675309)Left 8675309>>>void (Right 8675309)Right ()
Replace every element of a list with unit:
>>>void [1,2,3][(),(),()]
Replace the second element of a pair with unit:
>>>void (1,2)(1,())
Discard the result of an IO action:
>>>mapM print [1,2]1 2 [(),()]>>>void $ mapM print [1,2]1 2
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
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap.
The name of this operator is an allusion to $.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $ is function application, <$> is function
application lifted over a Functor.
Examples
Convert from a to a Maybe Int using Maybe
Stringshow:
>>>show <$> NothingNothing>>>show <$> Just 3Just "3"
Convert from an to an
Either Int IntEither IntString using show:
>>>show <$> Left 17Left 17>>>show <$> Right 17Right "17"
Double each element of a list:
>>>(*2) <$> [1,2,3][2,4,6]
Apply even to the second element of a pair:
>>>even <$> (2,2)(2,True)
readMaybe :: Read a => String -> Maybe a #
Parse a string using the Read instance.
Succeeds if there is exactly one valid result.
>>>readMaybe "123" :: Maybe IntJust 123
>>>readMaybe "hello" :: Maybe IntNothing
Since: base-4.6.0.0
coerce :: forall {k :: RuntimeRep} (a :: TYPE k) (b :: TYPE k). Coercible a b => a -> b #
The function coerce allows you to safely convert between values of
types that have the same representation with no run-time overhead. In the
simplest case you can use it instead of a newtype constructor, to go from
the newtype's concrete type to the abstract type. But it also works in
more complicated settings, e.g. converting a list of newtypes to a list of
concrete types.
When used in conversions involving a newtype wrapper, make sure the newtype constructor is in scope.
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
Examples
>>>newtype TTL = TTL Int deriving (Eq, Ord, Show)>>>newtype Age = Age Int deriving (Eq, Ord, Show)>>>coerce (Age 42) :: TTLTTL 42>>>coerce (+ (1 :: Int)) (Age 42) :: TTLTTL 43>>>coerce (map (+ (1 :: Int))) [Age 42, Age 24] :: [TTL][TTL 43,TTL 25]
for :: (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) #
mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) #
Map each element of a structure to a monadic action, evaluate
these actions from left to right, and collect the results. For
a version that ignores the results see mapM_.
Examples
sequence :: (Traversable t, Monad m) => t (m a) -> m (t a) #
Evaluate each monadic action in the structure from left to
right, and collect the results. For a version that ignores the
results see sequence_.
Examples
Basic usage:
The first two examples are instances where the input and
and output of sequence are isomorphic.
>>>sequence $ Right [1,2,3,4][Right 1,Right 2,Right 3,Right 4]
>>>sequence $ [Right 1,Right 2,Right 3,Right 4]Right [1,2,3,4]
The following examples demonstrate short circuit behavior
for sequence.
>>>sequence $ Left [1,2,3,4]Left [1,2,3,4]
>>>sequence $ [Left 0, Right 1,Right 2,Right 3,Right 4]Left 0
forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) #
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Examples
A common use of forever is to process input from network sockets,
Handles, and channels
(e.g. MVar and
Chan).
For example, here is how we might implement an echo
server, using
forever both to listen for client connections on a network socket
and to echo client input on client connection handles:
echoServer :: Socket -> IO () echoServer socket =forever$ do client <- accept socketforkFinally(echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client =forever$ hGetLine client >>= hPutStrLn client
Note that "forever" isn't necessarily non-terminating.
If the action is in a and short-circuits after some number of iterations.
then MonadPlus actually returns forevermzero, effectively short-circuiting its caller.
try :: (MonadUnliftIO m, Exception e) => m a -> m (Either e a) #
sortOn :: Ord b => (a -> b) -> [a] -> [a] #
Sort a list by comparing the results of a key function applied to each
element. is equivalent to sortOn f, but has the
performance advantage of only evaluating sortBy (comparing f)f once for each element in the
input list. This is called the decorate-sort-undecorate paradigm, or
Schwartzian transform.
Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input.
>>>sortOn fst [(2, "world"), (4, "!"), (1, "Hello")][(1,"Hello"),(2,"world"),(4,"!")]
The argument must be finite.
Since: base-4.8.0.0
The trace function outputs the trace message given as its first argument,
before returning the second argument as its result.
For example, this returns the value of f x and outputs the message to stderr.
Depending on your terminal (settings), they may or may not be mixed.
>>>let x = 123; f = show>>>trace ("calling f with x = " ++ show x) (f x)calling f with x = 123 "123"
The trace function should only be used for debugging, or for monitoring
execution. The function is not referentially transparent: its type indicates
that it is a pure function but it has the side effect of outputting the
trace message.
(>>>) :: 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
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)
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
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
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
(<**>) :: Applicative f => f a -> f (a -> b) -> f b infixl 4 #
A variant of <*> with the arguments reversed.
liftA :: Applicative f => (a -> b) -> f a -> f b #
Lift a function to actions.
Equivalent to Functor's fmap but implemented using only Applicative's methods:
liftA f a = pure f <*> a
As such this function may be used to implement a Functor instance from an Applicative one.
Examples
Using the Applicative instance for Lists:
>>>liftA (+1) [1, 2][2,3]
Or the Applicative instance for Maybe
>>>liftA (+1) (Just 3)Just 4
liftA3 :: Applicative f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d #
Lift a ternary function to actions.
(=<<) :: Monad m => (a -> m b) -> m a -> m b infixr 1 #
Same as >>=, but with the arguments interchanged.
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.
liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r #
Promote a function to a monad, scanning the monadic arguments from left to right. For example,
liftM2 (+) [0,1] [0,2] = [0,2,1,3] liftM2 (+) (Just 1) Nothing = Nothing
liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2).
liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2).
liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r #
Promote a function to a monad, scanning the monadic arguments from
left to right (cf. liftM2).
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
maybeToList :: Maybe a -> [a] #
The maybeToList function returns an empty list when given
Nothing or a singleton list when given Just.
Examples
Basic usage:
>>>maybeToList (Just 7)[7]
>>>maybeToList Nothing[]
One can use maybeToList to avoid pattern matching when combined
with a function that (safely) works on lists:
>>>import Text.Read ( readMaybe )>>>sum $ maybeToList (readMaybe "3")3>>>sum $ maybeToList (readMaybe "")0
listToMaybe :: [a] -> Maybe a #
The listToMaybe function returns Nothing on an empty list
or where Just aa is the first element of the list.
Examples
Basic usage:
>>>listToMaybe []Nothing
>>>listToMaybe [9]Just 9
>>>listToMaybe [1,2,3]Just 1
Composing maybeToList with listToMaybe should be the identity
on singleton/empty lists:
>>>maybeToList $ listToMaybe [5][5]>>>maybeToList $ listToMaybe [][]
But not on lists with more than one element:
>>>maybeToList $ listToMaybe [1,2,3][1]
catMaybes :: [Maybe a] -> [a] #
The catMaybes function takes a list of Maybes and returns
a list of all the Just values.
Examples
Basic usage:
>>>catMaybes [Just 1, Nothing, Just 3][1,3]
When constructing a list of Maybe values, catMaybes can be used
to return all of the "success" results (if the list is the result
of a map, then mapMaybe would be more appropriate):
>>>import Text.Read ( readMaybe )>>>[readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][Just 1,Nothing,Just 3]>>>catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][1,3]
mapMaybe :: Filterable f => (a -> Maybe b) -> f a -> f b #
Like mapMaybe.
foldl1' :: HasCallStack => (a -> a -> a) -> [a] -> a #
A strict version of foldl1.
byteSwap16 :: Word16 -> Word16 #
Reverse order of bytes in Word16.
Since: base-4.7.0.0
byteSwap32 :: Word32 -> Word32 #
Reverse order of bytes in Word32.
Since: base-4.7.0.0
byteSwap64 :: Word64 -> Word64 #
Reverse order of bytes in Word64.
Since: base-4.7.0.0
bitReverse8 :: Word8 -> Word8 #
Reverse the order of the bits in a Word8.
Since: base-4.14.0.0
bitReverse16 :: Word16 -> Word16 #
Reverse the order of the bits in a Word16.
Since: base-4.14.0.0
bitReverse32 :: Word32 -> Word32 #
Reverse the order of the bits in a Word32.
Since: base-4.14.0.0
bitReverse64 :: Word64 -> Word64 #
Reverse the order of the bits in a Word64.
Since: base-4.14.0.0
($>) :: Functor f => f a -> b -> f b infixl 4 #
Flipped version of <$.
Examples
Replace the contents of a with a constant
Maybe IntString:
>>>Nothing $> "foo"Nothing>>>Just 90210 $> "foo"Just "foo"
Replace the contents of an
with a constant Either Int IntString, resulting in an :Either
Int String
>>>Left 8675309 $> "foo"Left 8675309>>>Right 8675309 $> "foo"Right "foo"
Replace each element of a list with a constant String:
>>>[1,2,3] $> "foo"["foo","foo","foo"]
Replace the second element of a pair with a constant String:
>>>(1,2) $> "foo"(1,"foo")
Since: base-4.7.0.0
optional :: Alternative f => f a -> f (Maybe a) #
One or none.
It is useful for modelling any computation that is allowed to fail.
Examples
Using the Alternative instance of Control.Monad.Except, the following functions:
>>>import Control.Monad.Except
>>>canFail = throwError "it failed" :: Except String Int>>>final = return 42 :: Except String Int
Can be combined by allowing the first function to fail:
>>>runExcept $ canFail *> finalLeft "it failed">>>runExcept $ optional canFail *> finalRight 42
partitionEithers :: [Either a b] -> ([a], [b]) #
Partitions a list of Either into two lists.
All the Left elements are extracted, in order, to the first
component of the output. Similarly the Right elements are extracted
to the second component of the output.
Examples
Basic usage:
>>>let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]>>>partitionEithers list(["foo","bar","baz"],[3,7])
The pair returned by should be the same
pair as partitionEithers x(:lefts x, rights x)
>>>let list = [ Left "foo", Right 3, Left "bar", Right 7, Left "baz" ]>>>partitionEithers list == (lefts list, rights list)True
isLeft :: Either a b -> Bool #
Return True if the given value is a Left-value, False otherwise.
Examples
Basic usage:
>>>isLeft (Left "foo")True>>>isLeft (Right 3)False
Assuming a Left value signifies some sort of error, we can use
isLeft to write a very simple error-reporting function that does
absolutely nothing in the case of success, and outputs "ERROR" if
any error occurred.
This example shows how isLeft might be used to avoid pattern
matching when one does not care about the value contained in the
constructor:
>>>import Control.Monad ( when )>>>let report e = when (isLeft e) $ putStrLn "ERROR">>>report (Right 1)>>>report (Left "parse error")ERROR
Since: base-4.7.0.0
isRight :: Either a b -> Bool #
Return True if the given value is a Right-value, False otherwise.
Examples
Basic usage:
>>>isRight (Left "foo")False>>>isRight (Right 3)True
Assuming a Left value signifies some sort of error, we can use
isRight to write a very simple reporting function that only
outputs "SUCCESS" when a computation has succeeded.
This example shows how isRight might be used to avoid pattern
matching when one does not care about the value contained in the
constructor:
>>>import Control.Monad ( when )>>>let report e = when (isRight e) $ putStrLn "SUCCESS">>>report (Left "parse error")>>>report (Right 1)SUCCESS
Since: base-4.7.0.0
fromLeft :: a -> Either a b -> a #
Return the contents of a Left-value or a default value otherwise.
Examples
Basic usage:
>>>fromLeft 1 (Left 3)3>>>fromLeft 1 (Right "foo")1
Since: base-4.10.0.0
fromRight :: b -> Either a b -> b #
Return the contents of a Right-value or a default value otherwise.
Examples
Basic usage:
>>>fromRight 1 (Right 3)3>>>fromRight 1 (Left "foo")1
Since: base-4.10.0.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" "!"
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
sequence_ :: (Foldable t, Monad m) => t (m a) -> m () #
Evaluate each monadic action in the structure from left to right,
and ignore the results. For a version that doesn't ignore the
results see sequence.
sequence_ is just like sequenceA_, but specialised to monadic
actions.
asum :: (Foldable t, Alternative f) => t (f a) -> f a #
The sum of a collection of actions using (<|>), generalizing concat.
asum is just like msum, but generalised to Alternative.
Examples
Basic usage:
>>>asum [Just "Hello", Nothing, Just "World"]Just "Hello"
The traceIO function outputs the trace message from the IO monad.
This sequences the output with respect to other IO actions.
Since: base-4.5.0.0
filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a] #
This generalizes the list-based filter function.
(>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c infixr 1 #
Left-to-right composition of Kleisli arrows.
'(bs ' can be understood as the >=> cs) ado expression
do b <- bs a cs b
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #
The mapAndUnzipM function maps its first argument over a list, returning
the result as a pair of lists. This function is mainly used with complicated
data structures or a state monad.
zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c] #
zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m () #
foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
The foldM function is analogous to foldl, except that its result is
encapsulated in a monad. Note that foldM works from left-to-right over
the list arguments. This could be an issue where ( and the `folded
function' are not commutative.>>)
foldM f a1 [x1, x2, ..., xm] == do a2 <- f a1 x1 a3 <- f a2 x2 ... f am xm
If right-to-left evaluation is required, the input list should be reversed.
foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m () #
Like foldM, but discards the result.
replicateM :: Applicative m => Int -> m a -> m [a] #
performs the action replicateM n actact n times,
and then returns the list of results:
Examples
>>>import Control.Monad.State>>>runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1([1,2,3],4)
replicateM_ :: Applicative m => Int -> m a -> m () #
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when.
traceMarkerIO :: String -> IO () #
The traceMarkerIO function emits a marker to the eventlog, if eventlog
profiling is available and enabled at runtime.
Compared to traceMarker, traceMarkerIO sequences the event with respect to
other IO actions.
Since: base-4.7.0.0
traceMarker :: String -> a -> a #
The traceMarker function emits a marker to the eventlog, if eventlog
profiling is available and enabled at runtime. The String is the name of
the marker. The name is just used in the profiling tools to help you keep
clear which marker is which.
This function is suitable for use in pure code. In an IO context use
traceMarkerIO instead.
Note that when using GHC's SMP runtime, it is possible (but rare) to get
duplicate events emitted if two CPUs simultaneously evaluate the same thunk
that uses traceMarker.
Since: base-4.7.0.0
traceEventIO :: String -> IO () #
The traceEventIO function emits a message to the eventlog, if eventlog
profiling is available and enabled at runtime.
Compared to traceEvent, traceEventIO sequences the event with respect to
other IO actions.
Since: base-4.5.0.0
traceEvent :: String -> a -> a #
The traceEvent function behaves like trace with the difference that
the message is emitted to the eventlog, if eventlog profiling is available
and enabled at runtime.
It is suitable for use in pure code. In an IO context use traceEventIO
instead.
Note that when using GHC's SMP runtime, it is possible (but rare) to get
duplicate events emitted if two CPUs simultaneously evaluate the same thunk
that uses traceEvent.
Since: base-4.5.0.0
traceStack :: String -> a -> a #
like trace, but additionally prints a call stack if one is
available.
In the current GHC implementation, the call stack is only
available if the program was compiled with -prof; otherwise
traceStack behaves exactly like trace. Entries in the call
stack correspond to SCC annotations, so it is a good idea to use
-fprof-auto or -fprof-auto-calls to add SCC annotations automatically.
Since: base-4.5.0.0
traceShowM :: (Show a, Applicative f) => a -> f () #
traceM :: Applicative f => String -> f () #
Like trace but returning unit in an arbitrary Applicative context. Allows
for convenient use in do-notation.
Note that the application of traceM is not an action in the Applicative
context, as traceIO is in the IO type. While the fresh bindings in the
following example will force the traceM expressions to be reduced every time
the do-block is executed, traceM "not crashed" would only be reduced once,
and the message would only be printed once. If your monad is in
MonadIO,
may be a better option.liftIO . traceIO
>>>:{do x <- Just 3 traceM ("x: " ++ show x) y <- pure 12 traceM ("y: " ++ show y) pure (x*2 + y) :} x: 3 y: 12 Just 18
Since: base-4.7.0.0
traceShowId :: Show a => a -> a #
Like traceShow but returns the shown value instead of a third value.
>>>traceShowId (1+2+3, "hello" ++ "world")(6,"helloworld") (6,"helloworld")
Since: base-4.7.0.0
Like trace but returns the message instead of a third value.
>>>traceId "hello"hello "hello"
Since: base-4.7.0.0
putTraceMsg :: String -> IO () #
traceWith :: (a -> String) -> a -> a #
Like trace, but outputs the result of calling a function on the argument.
>>>traceWith fst ("hello","world")hello ("hello","world")
Since: base-4.18.0.0
traceShowWith :: Show b => (a -> b) -> a -> a #
traceEventWith :: (a -> String) -> a -> a #
Like traceEvent, but emits the result of calling a function on its
argument.
Since: base-4.18.0.0
flushEventLog :: IO () #
Immediately flush the event log, if enabled.
Since: base-4.15.0.0
mapLeft :: (a -> c) -> Either a b -> Either c b #
The mapLeft function takes a function and applies it to an Either value
iff the value takes the form .Left _
Using Data.Bifunctor:
mapLeft = first
Using Control.Arrow:
mapLeft= (left)
Using Control.Lens:
mapLeft = over _Left
>>>mapLeft (*2) (Left 4)Left 8
>>>mapLeft (*2) (Right "hello")Right "hello"
maybeToRight :: b -> Maybe a -> Either b a #
mapMaybeM :: Monad m => (a -> m (Maybe b)) -> [a] -> m [b] #
A version of mapMaybe that works with a monadic predicate.
encodeUtf8 :: Text -> ByteString #
Encode text using UTF-8 encoding.
decodeUtf8 :: ByteString -> Text #
Decode a ByteString containing UTF-8 encoded text that is known
to be valid.
If the input contains any invalid UTF-8 data, an exception will be
thrown that cannot be caught in pure code. For more control over
the handling of invalid data, use decodeUtf8' or
decodeUtf8With.
This is a partial function: it checks that input is a well-formed UTF-8 sequence and copies buffer or throws an error otherwise.
askUnliftIO :: MonadUnliftIO m => m (UnliftIO m) #
Capture the current monadic context, providing the ability to
run monadic actions in IO.
See UnliftIO for an explanation of why we need a helper
datatype here.
Prior to version 0.2.0.0 of this library, this was a method in the
MonadUnliftIO type class. It was moved out due to
https://github.com/fpco/unliftio/issues/55.
Since: unliftio-core-0.1.0.0
askRunInIO :: MonadUnliftIO m => m (m a -> IO a) #
Same as askUnliftIO, but returns a monomorphic function
instead of a polymorphic newtype wrapper. If you only need to apply
the transformation on one concrete type, this function can be more
convenient.
Since: unliftio-core-0.1.0.0
withUnliftIO :: MonadUnliftIO m => (UnliftIO m -> IO a) -> m a #
Convenience function for capturing the monadic context and running
an IO action. The UnliftIO newtype wrapper is rarely needed, so
prefer withRunInIO to this function.
Since: unliftio-core-0.1.0.0
into :: forall target source. From source target => source -> target #
This is the same as from except that the type variables are in the
opposite order.
-- Avoid this: from x :: t -- Prefer this: into @t x
tryInto :: forall target source. TryFrom source target => source -> Either (TryFromException source target) target #
This is the same as tryFrom except that the type variables are
in the opposite order.
-- Avoid this: tryFrom x :: Either (TryFromException s t) t -- Prefer this: tryInto @t x
wither :: (Witherable t, Applicative f) => (a -> f (Maybe b)) -> t a -> f (t b) #
filterA :: (Witherable t, Applicative f) => (a -> f Bool) -> t a -> f (t a) #
witherMap :: (Witherable t, Applicative m) => (t b -> r) -> (a -> m (Maybe b)) -> t a -> m r #
forMaybe :: (Witherable t, Applicative f) => t a -> (a -> f (Maybe b)) -> f (t b) #
readUtf8 :: FilePath -> IO Text Source #
Strictly read an entire file decoding UTF8. Converts rn -> n on windows.
safeReadUtf8 :: FilePath -> IO (Either IOException Text) Source #
Strictly read from a handle, decoding UTF8, or failing if not valid UTF8 Converts rn -> n on windows.
safeReadUtf8StdIn :: IO (Either IOException Text) Source #
Strictly read from stdin, decoding UTF8. Converts rn -> n on windows.
writeUtf8 :: FilePath -> Text -> IO () Source #
Write a file strictly assuming UTF8 Converts n -> rn on windows.
prependUtf8 :: FilePath -> Text -> IO () Source #
Atomically prepend some text to a file, creating the file if it doesn't already exist
wundefined :: HasCallStack => a Source #
Warning: You left this wundefined.
Bool control flow
onFalse :: Applicative m => m () -> Bool -> m () Source #
condition & onFalse do shortCircuit
onTrue :: Applicative m => m () -> Bool -> m () Source #
condition & onTrue do shortCircuit
Maybe control flow
onNothing :: Applicative m => m a -> Maybe a -> m a Source #
E.g.
@
onNothing (throwIO MissingPerson) $ mayThing
@
onNothingM :: Monad m => m a -> m (Maybe a) -> m a Source #
whenNothing :: Applicative m => Maybe a -> m a -> m a Source #
E.g. maybePerson whenNothing throwIO MissingPerson
whenNothingM :: Monad m => m (Maybe a) -> m a -> m a Source #
whenJust :: Applicative m => Maybe a -> (a -> m ()) -> m () Source #
eitherToMaybe :: Either a b -> Maybe b #
maybeToEither :: a -> Maybe b -> Either a b #
eitherToThese :: Either a b -> These a b Source #
altMap :: (Alternative f, Foldable t) => (a -> f b) -> t a -> f b Source #
Like foldMap but for Alternative.
hoistMaybe :: Applicative m => Maybe a -> MaybeT m a Source #
Can be removed when we upgrade transformers to a more recent version.
Either control flow
onLeft :: Applicative m => (a -> m b) -> Either a b -> m b Source #
whenLeft :: Applicative m => Either a b -> (a -> m b) -> m b Source #
throwEitherMWith :: forall e e' m a. (MonadIO m, Exception e') => (e -> e') -> m (Either e a) -> m a Source #
Basic lensy stuff we use all over
(^.) :: s -> Getting a s a -> a infixl 8 #
View the value pointed to by a Getter or Lens or the
result of folding over all the results of a Fold or
Traversal that points at a monoidal values.
This is the same operation as view with the arguments flipped.
The fixity and semantics are such that subsequent field accesses can be
performed with (.).
>>>(a,b)^._2b
>>>("hello","world")^._2"world"
>>>import Data.Complex>>>((0, 1 :+ 2), 3)^._1._2.to magnitude2.23606797749979
(^.) :: s ->Getters a -> a (^.) ::Monoidm => s ->Folds m -> m (^.) :: s ->Iso's a -> a (^.) :: s ->Lens's a -> a (^.) ::Monoidm => s ->Traversal's m -> m
(.~) :: ASetter s t a b -> b -> s -> t infixr 4 #
Replace the target of a Lens or all of the targets of a Setter
or Traversal with a constant value.
This is an infix version of set, provided for consistency with (.=).
f<$a ≡mapped.~f$a
>>>(a,b,c,d) & _4 .~ e(a,b,c,e)
>>>(42,"world") & _1 .~ "hello"("hello","world")
>>>(a,b) & both .~ c(c,c)
(.~) ::Setters t a b -> b -> s -> t (.~) ::Isos t a b -> b -> s -> t (.~) ::Lenss t a b -> b -> s -> t (.~) ::Traversals t a b -> b -> s -> t
(%~) :: ASetter s t a b -> (a -> b) -> s -> t infixr 4 #
Modifies the target of a Lens or all of the targets of a Setter or
Traversal with a user supplied function.
This is an infix version of over.
fmapf ≡mapped%~ffmapDefaultf ≡traverse%~f
>>>(a,b,c) & _3 %~ f(a,b,f c)
>>>(a,b) & both %~ f(f a,f b)
>>>_2 %~ length $ (1,"hello")(1,5)
>>>traverse %~ f $ [a,b,c][f a,f b,f c]
>>>traverse %~ even $ [1,2,3][False,True,False]
>>>traverse.traverse %~ length $ [["hello","world"],["!!!"]][[5,5],[3]]
(%~) ::Setters t a b -> (a -> b) -> s -> t (%~) ::Isos t a b -> (a -> b) -> s -> t (%~) ::Lenss t a b -> (a -> b) -> s -> t (%~) ::Traversals t a b -> (a -> b) -> s -> t
view :: MonadReader s m => Getting a s a -> m a #
View the value pointed to by a Getter, Iso or
Lens or the result of folding over all the results of a
Fold or Traversal that points
at a monoidal value.
view.to≡id
>>>view (to f) af a
>>>view _2 (1,"hello")"hello"
>>>view (to succ) 56
>>>view (_2._1) ("hello",("world","!!!"))"world"
As view is commonly used to access the target of a Getter or obtain a monoidal summary of the targets of a Fold,
It may be useful to think of it as having one of these more restricted signatures:
view::Getters a -> s -> aview::Monoidm =>Folds m -> s -> mview::Iso's a -> s -> aview::Lens's a -> s -> aview::Monoidm =>Traversal's m -> s -> m
In a more general setting, such as when working with a Monad transformer stack you can use:
view::MonadReaders m =>Getters a -> m aview:: (MonadReaders m,Monoida) =>Folds a -> m aview::MonadReaders m =>Iso's a -> m aview::MonadReaders m =>Lens's a -> m aview:: (MonadReaders m,Monoida) =>Traversal's a -> m a
set :: ASetter s t a b -> b -> s -> t #
Replace the target of a Lens or all of the targets of a Setter
or Traversal with a constant value.
(<$) ≡setmapped
>>>set _2 "hello" (1,())(1,"hello")
>>>set mapped () [1,2,3,4][(),(),(),()]
Note: Attempting to set a Fold or Getter will fail at compile time with an
relatively nice error message.
set::Setters t a b -> b -> s -> tset::Isos t a b -> b -> s -> tset::Lenss t a b -> b -> s -> tset::Traversals t a b -> b -> s -> t
over :: ASetter s t a b -> (a -> b) -> s -> t #
Modify the target of a Lens or all the targets of a Setter or Traversal
with a function.
fmap≡overmappedfmapDefault≡overtraversesets.over≡idover.sets≡id
Given any valid Setter l, you can also rely on the law:
overl f.overl g =overl (f.g)
e.g.
>>>over mapped f (over mapped g [a,b,c]) == over mapped (f . g) [a,b,c]True
Another way to view over is to say that it transforms a Setter into a
"semantic editor combinator".
>>>over mapped f (Just a)Just (f a)
>>>over mapped (*10) [1,2,3][10,20,30]
>>>over _1 f (a,b)(f a,b)
>>>over _1 show (10,20)("10",20)
over::Setters t a b -> (a -> b) -> s -> tover::ASetters t a b -> (a -> b) -> s -> t