Desugaring monad. See also TcM.
Moduleghc-9.10.3GHC2021
GHC.HsToCore.Monad
- 10 types
- 1 class
- 54 values
- Packageghc-9.10.3
- Exports66
- LanguageGHC2021
- LicenceBSD-3-Clause
- SourceTypes.hs
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 Data.Foldable.mapM_.
Examples
mapM is literally a traverse with a type signature restricted to Monad. Its implementation may be more efficient due to additional power of Monad.
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.
Left-to-right monadic fold over the elements of a structure.
Given a structure t with elements (a, b, ..., w, x, y), the result of
a fold with an operator function f is equivalent to:
foldlM f z t = do
aa <- f z a
bb <- f aa b
...
xx <- f ww x
yy <- f xx y
return yy -- Just @return z@ when the structure is emptyFor a Monad m, given two functions f1 :: a -> m b and f2 :: b -> m c,
their Kleisli composition (f1 >=> f2) :: a -> m c is defined by:
(f1 >=> f2) a = f1 a >>= f2Another way of thinking about foldlM is that it amounts to an application
to z of a Kleisli composition:
foldlM f z t =
flip f a >=> flip f b >=> ... >=> flip f x >=> flip f y $ zThe monadic effects of foldlM are sequenced from left to right.
If at some step the bind operator (>>=) short-circuits (as with, e.g.,
mzero in a MonadPlus), the evaluated effects will be from an initial
segment of the element sequence. If you want to evaluate the monadic
effects in right-to-left order, or perhaps be able to short-circuit after
processing a tail of the sequence of elements, you'll need to use foldrM
instead.
If the monadic effects don't short-circuit, the outermost application of
f is to the rightmost element y, so that, ignoring effects, the result
looks like a left fold:
((((z `f` a) `f` b) ... `f` w) `f` x) `f` yExamples
Basic usage:
let f a e = do { print e ; return $ e : a }foldlM f [] [0..3]0123[3,2,1,0]
Right-to-left monadic fold over the elements of a structure.
Given a structure t with elements (a, b, c, ..., x, y), the result of
a fold with an operator function f is equivalent to:
foldrM f z t = do
yy <- f y z
xx <- f x yy
...
bb <- f b cc
aa <- f a bb
return aa -- Just @return z@ when the structure is emptyFor a Monad m, given two functions f1 :: a -> m b and f2 :: b -> m c,
their Kleisli composition (f1 >=> f2) :: a -> m c is defined by:
(f1 >=> f2) a = f1 a >>= f2Another way of thinking about foldrM is that it amounts to an application
to z of a Kleisli composition:
foldrM f z t = f y >=> f x >=> ... >=> f b >=> f a $ zThe monadic effects of foldrM are sequenced from right to left, and e.g.
folds of infinite lists will diverge.
If at some step the bind operator (>>=) short-circuits (as with, e.g.,
mzero in a MonadPlus), the evaluated effects will be from a tail of the
element sequence. If you want to evaluate the monadic effects in
left-to-right order, or perhaps be able to short-circuit after an initial
sequence of elements, you'll need to use foldlM instead.
If the monadic effects don't short-circuit, the outermost application of
f is to the leftmost element a, so that, ignoring effects, the result
looks like a right fold:
a `f` (b `f` (c `f` (... (x `f` (y `f` z))))).Examples
Basic usage:
let f i acc = do { print i ; return $ i : acc }foldrM f [] [0..3]3210[0,1,2,3]
A functor with application, providing operations to
A minimal complete definition must include implementations of pure and of either <*> or liftA2. If it defines both, then they must behave the same as their default definitions:
(<*>) = liftA2 idliftA2 f x y = f Prelude.<$> x <*> yFurther, any definition must satisfy the following:
- Identity
pure id <*> v = v- Composition
pure (.) <*> u <*> v <*> w = u <*> (v <*> w)- Homomorphism
pure f <*> pure x = pure (f x)- Interchange
u <*> pure y = pure ($ y) <*> u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor instance for f will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g yit follows from the above that
liftA2 p (liftA2 q u v) = liftA2 f u . liftA2 g vIf f is also a Monad, it should satisfy
(which implies that pure and <*> satisfy the applicative functor laws).
Methods
pure :: a -> f aLift a value into the Structure.
Examples
Example1 expression pure 1 :: Maybe IntJust 1
Example1 expression pure 'z' :: [Char]"z"
Example1 expression pure (pure ":D") :: Maybe [String]Just [":D"]
(<*>) :: f (a -> b) -> f a -> f binfixl 4Sequential application.
A few functors support an implementation of <*> that is more efficient than the default one.
Example
Used in combination with
,(Data.Functor.<$>)can be used to build a record.(<*>)Example1 expression data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}Example3 expressions produceFoo :: Applicative f => f FooproduceBar :: Applicative f => f BarproduceBaz :: Applicative f => f Baz
Example2 expressions mkState :: Applicative f => f MyStatemkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
liftA2 :: (a -> b -> c) -> f a -> f b -> f cLift 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
Example1 expression liftA2 (,) (Just 3) (Just 5)Just (3,5)
Example1 expression liftA2 (+) [1, 2, 3] [4, 5, 6][5,6,7,6,7,8,7,8,9]
(*>) :: f a -> f b -> f binfixl 4Sequence 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.
Example1 expression Just 2 *> Just 3Just 3
Example1 expression Nothing *> Just 3Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
Example4 expressions import Data.Charimport GHC.Internal.Text.ParserCombinators.ReadPlet p = string "my name is " *> munch1 isAlpha <* eofreadP_to_S p "my name is Simon"[("Simon","")]
(<*) :: f a -> f b -> f ainfixl 4Sequence actions, discarding the value of the second argument.
Instances154Applicative, …
Applicative ComplexDefined in base-4.20.2.0 · Data.ComplexApplicative FirstDefined in base-4.20.2.0 · Data.SemigroupApplicative LastDefined in base-4.20.2.0 · Data.SemigroupApplicative MaxDefined in base-4.20.2.0 · Data.SemigroupApplicative MinDefined in base-4.20.2.0 · Data.SemigroupApplicative GetDefined in binary-0.8.9.3 · Data.Binary.Get.InternalApplicative PutMDefined in binary-0.8.9.3 · Data.Binary.PutApplicative PutDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.InternalApplicative SeqDefined in containers-0.7 · Data.Sequence.InternalApplicative TreeDefined in containers-0.7 · Data.TreeApplicative AssemblerDefined in ghc-9.10.3 · GHC.ByteCode.AsmApplicative CmmOptMDefined in ghc-9.10.3 · GHC.Cmm.GenericOptApplicative CmmLintDefined in ghc-9.10.3 · GHC.Cmm.LintApplicative PDDefined in ghc-9.10.3 · GHC.Cmm.Parser.MonadApplicative NatMDefined in ghc-9.10.3 · GHC.CmmToAsm.MonadApplicative WasmAsmMDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.AsmApplicative TEDefined in ghc-9.10.3 · GHC.CmmToCApplicative LlvmMDefined in ghc-9.10.3 · GHC.CmmToLlvm.BaseApplicative NormMDefined in ghc-9.10.3 · GHC.Core.FamInstEnvApplicative LintMDefined in ghc-9.10.3 · GHC.Core.LintApplicative RuleMDefined in ghc-9.10.3 · GHC.Core.Opt.ConstantFoldApplicative CoreMDefined in ghc-9.10.3 · GHC.Core.Opt.MonadApplicative SimplMDefined in ghc-9.10.3 · GHC.Core.Opt.Simplify.MonadApplicative UMDefined in ghc-9.10.3 · GHC.Core.UnifyApplicative UnifyResultMDefined in ghc-9.10.3 · GHC.Core.UnifyApplicative CtsMDefined in ghc-9.10.3 · GHC.CoreToStgApplicative NullCollapseVizDefined in ghc-9.10.3 · GHC.Data.Graph.CollapseApplicative InfiniteDefined in ghc-9.10.3 · GHC.Data.List.InfiniteApplicative PairDefined in ghc-9.10.3 · GHC.Data.PairApplicative MaybeDefined in ghc-9.10.3 · GHC.Data.StrictApplicative HscDefined in ghc-9.10.3 · GHC.Driver.Env.TypesApplicative GhcDefined in ghc-9.10.3 · GHC.Driver.MonadApplicative HookedUseDefined in ghc-9.10.3 · GHC.Driver.Pipeline.ExecuteApplicative MatchResultDefined in ghc-9.10.3 · GHC.HsToCore.MonadProduct is an "or" on fallibility---the combined match result is infallible only if the left and right argument match results both were.
This is useful for combining a bunch of alternatives together and then getting the overall fallibility of the entire group. See
mkDataConCasefor an example.Applicative TMDefined in ghc-9.10.3 · GHC.HsToCore.TicksApplicative DFFVDefined in ghc-9.10.3 · GHC.Iface.TidyApplicative PDefined in ghc-9.10.3 · GHC.Parser.LexerApplicative PVDefined in ghc-9.10.3 · GHC.Parser.PostProcessApplicative HdkADefined in ghc-9.10.3 · GHC.Parser.PostProcess.HaddockApplicative HdkMDefined in ghc-9.10.3 · GHC.Parser.PostProcess.HaddockApplicative CpsRnDefined in ghc-9.10.3 · GHC.Rename.PatApplicative TPRnMDefined in ghc-9.10.3 · GHC.Rename.PatApplicative RMDefined in ghc-9.10.3 · GHC.Stg.InferTags.RewriteApplicative LiftMDefined in ghc-9.10.3 · GHC.Stg.Lift.MonadApplicative LintMDefined in ghc-9.10.3 · GHC.Stg.LintApplicative StgMDefined in ghc-9.10.3 · GHC.Stg.PipelineApplicative BcMDefined in ghc-9.10.3 · GHC.StgToByteCodeApplicative CmmParseDefined in ghc-9.10.3 · GHC.StgToCmm.ExtCodeApplicative FCodeDefined in ghc-9.10.3 · GHC.StgToCmm.MonadApplicative KindRepMDefined in ghc-9.10.3 · GHC.Tc.Instance.TypeableApplicative SolverStageDefined in ghc-9.10.3 · GHC.Tc.Solver.MonadApplicative TcSDefined in ghc-9.10.3 · GHC.Tc.Solver.MonadApplicative RewriteMDefined in ghc-9.10.3 · GHC.Tc.Solver.RewriteApplicative RoleMDefined in ghc-9.10.3 · GHC.Tc.TyCl.UtilsApplicative SynCycleMDefined in ghc-9.10.3 · GHC.Tc.TyCl.UtilsApplicative TcPluginMDefined in ghc-9.10.3 · GHC.Tc.TypesApplicative ZonkMDefined in ghc-9.10.3 · GHC.Tc.Zonk.MonadApplicative UniqSMDefined in ghc-9.10.3 · GHC.Types.Unique.SupplyApplicative NonEmptyDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative STMDefined in ghc-internal-9.1003.0 · GHC.Internal.Conc.SyncApplicative IdentityDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityApplicative FirstDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidApplicative LastDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidApplicative DownDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.OrdApplicative DualDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative ProductDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative SumDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative ZipListDefined in ghc-internal-9.1003.0 · GHC.Internal.Functor.ZipListf <$> ZipList xs1 <*> ... <*> ZipList xsN = ZipList (zipWithN f xs1 ... xsN)where
zipWithNrefers to thezipWithfunction of the appropriate arity (zipWith,zipWith3,zipWith4, ...). For example:(\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"]}Applicative NoIODefined in ghc-internal-9.1003.0 · GHC.Internal.GHCiApplicative Par1Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative MaybeDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative PDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPApplicative ReadPDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPApplicative ReadPrecDefined in ghc-internal-9.1003.0 · GHC.Internal.Text.ParserCombinators.ReadPrecApplicative SoloDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative IODefined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative GHCiQDefined in ghci-9.10.3 · GHCi.THApplicative STMDefined in stm-2.5.3.1 · Control.Sequential.STMApplicative PprMDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.PprLibApplicative QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxApplicative []Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyApplicative U1Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative (SetM s)Defined in containers-0.7 · Data.GraphApplicative (State s)Defined in containers-0.7 · Utils.Containers.Internal.StateApplicative (RegM freeRegs)Defined in ghc-9.10.3 · GHC.CmmToAsm.Reg.Linear.StateApplicative (WasmCodeGenM w)Defined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesApplicative (IOEnv m)Defined in ghc-9.10.3 · GHC.Data.IOEnvApplicative (MaybeErr err)Defined in ghc-9.10.3 · GHC.Data.MaybeApplicative (CmdLineP s)Defined in ghc-9.10.3 · GHC.Driver.SessionApplicative (PuResult a)Defined in ghc-9.10.3 · GHC.Tc.Utils.UnifyApplicative (ZonkBndrT m)Defined in ghc-9.10.3 · GHC.Tc.Zonk.EnvApplicative (CvtM' err)Defined in ghc-9.10.3 · GHC.ThToHsApplicative (Codensity f)Defined in ghc-9.10.3 · GHC.Utils.Monad.CodensityApplicative (State s)Defined in ghc-9.10.3 · GHC.Utils.Monad.State.StrictApplicative (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Monad.ST.Lazy.ImpApplicative (Either e)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.EitherApplicative (StateL s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsApplicative (StateR s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsApplicative (ST s)Defined in ghc-internal-9.1003.0 · GHC.Internal.STApplicative f => Applicative (Lift f)Defined in transformers-0.6.1.1 · Control.Applicative.LiftA combination is Pure only if both parts are.
Applicative m => Applicative (GhcT m)Defined in ghc-9.10.3 · GHC.Driver.MonadApplicative m => Applicative (ZonkT m)Defined in ghc-9.10.3 · GHC.Tc.Zonk.EnvMonad m => Applicative (WrappedMonad m)Defined in base-4.20.2.0 · Control.ApplicativeMonad m => Applicative (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonad m => Applicative (EwM m)Defined in ghc-9.10.3 · GHC.Driver.CmdLineMonoid a => Applicative (Tuple2 a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseArrow a => Applicative (ArrowMonad a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.Arrow(Functor m, Monad m) => Applicative (MaybeT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeApplicative (S z s)Defined in ghc-9.10.3 · GHC.CmmToAsm.CFG.DominatorsApplicative (Stream m a)Defined in ghc-9.10.3 · GHC.Data.StreamApplicative (t m) => Applicative (LiftingAccum t m)Defined in mtl-2.3.1 · Control.Monad.AccumApplicative (t m) => Applicative (LiftingSelect t m)Defined in mtl-2.3.1 · Control.Monad.SelectApplicative f => Applicative (Ap f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidApplicative f => Applicative (Alt f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative f => Applicative (Rec1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative f => Applicative (Backwards f)Defined in transformers-0.6.1.1 · Control.Applicative.BackwardsApply
f-actions in the reverse order.Applicative f => Applicative (Reverse f)Defined in transformers-0.6.1.1 · Data.Functor.ReverseDerived instance.
Applicative m => Applicative (Kleisli m a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Control.ArrowApplicative m => Applicative (IdentityT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityApplicative m => Applicative (ReaderT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ReaderMonad m => Applicative (StreamS m a)Defined in ghc-9.10.3 · GHC.Data.StreamMonad m => Applicative (StateT s m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsMonoid a => Applicative (Constant a)Defined in transformers-0.6.1.1 · Data.Functor.ConstantMonoid m => Applicative (Const m)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstArrow a => Applicative (WrappedArrow a b)Defined in base-4.20.2.0 · Control.Applicative(Applicative f, Monad f) => Applicative (WhenMissing f x)Defined in containers-0.7 · Data.IntMap.InternalEquivalent to
ReaderT k (ReaderT x (MaybeT f)).(Applicative f, Monad f) => Applicative (WhenMissing f x)Defined in ghc-9.10.3 · GHC.Data.Word64Map.InternalEquivalent to
ReaderT k (ReaderT x (MaybeT f)).(Functor m, Monad m) => Applicative (ExceptT e m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Except(Functor m, Monad m) => Applicative (SelectT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Select(Functor m, Monad m) => Applicative (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.Lazy(Functor m, Monad m) => Applicative (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.Strict(Functor m, Monad m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Monoid a, Monoid b) => Applicative (Tuple3 a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base(Monoid w, Applicative m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, Applicative m) => Applicative (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Strict(Monoid w, Functor m, Monad m) => Applicative (AccumT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Accum(Generic1 f, Applicative (Rep1 f)) => Applicative (Generically1 f)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsApplicative (ContT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ContApplicative ((->) r)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid c => Applicative (K1 i c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Applicative f, Applicative g) => Applicative (Product f g)Defined in base-4.20.2.0 · Data.Functor.Product(Applicative f, Applicative g) => Applicative (f :*: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Applicative f, Monad f) => Applicative (WhenMissing f k x)Defined in containers-0.7 · Data.Map.InternalEquivalent to
ReaderT k (ReaderT x (MaybeT f)).(Monad f, Applicative f) => Applicative (WhenMatched f x y)Defined in containers-0.7 · Data.IntMap.InternalEquivalent to
ReaderT Key (ReaderT x (ReaderT y (MaybeT f)))(Monad f, Applicative f) => Applicative (WhenMatched f x y)Defined in ghc-9.10.3 · GHC.Data.Word64Map.InternalEquivalent to
ReaderT Key (ReaderT x (ReaderT y (MaybeT f)))(Monoid a, Monoid b, Monoid c) => Applicative (Tuple4 a b c)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseApplicative f => Applicative (M1 i c f)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Applicative f, Applicative g) => Applicative (Compose f g)Defined in base-4.20.2.0 · Data.Functor.Compose(Applicative f, Applicative g) => Applicative (f :.: g)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Functor m, Monad m) => Applicative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.CPS(Monad f, Applicative f) => Applicative (WhenMatched f k x y)Defined in containers-0.7 · Data.Map.InternalEquivalent to
ReaderT k (ReaderT x (ReaderT y (MaybeT f)))(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Lazy(Monoid w, Functor m, Monad m) => Applicative (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Strict
An infix synonym for fmap.
The name of this operator is an allusion to Prelude.$.
Note the similarities between their types:
($) :: (a -> b) -> a -> b
(<$>) :: Functor f => (a -> b) -> f a -> f bWhereas Prelude.$ is function application, <$> is function
application lifted over a Functor.
Examples
Convert from a Maybe Int to a Maybe
String using show:
show <$> NothingNothing
show <$> Just 3Just "3"
Convert from an Either Int Int to an
Either Int String 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)
Unique Supply
A value of type UniqSupply is unique, and it can
supply one distinct Unique. Also, from the supply, one can
also manufacture an arbitrary number of further UniqueSupply values,
which will be distinct from the first and from all others.
See getCCIndexM.
Get the current pattern match oracle state. See dsl_nablas.
Set the pattern match oracle state within the scope of the given action. See dsl_nablas.
The COMPLETE pragmas that are in scope.
Emit a diagnostic for the current source location. In case the diagnostic is a warning,
the latter will be ignored and discarded if the relevant WarningFlag is not set in the DynFlags.
See Note [Discarding Messages] in GHC.Types.Error.
Issue an error, but return the expression for (), so that we can continue reporting errors.
Constructors
Instances1Outputable
Outputable DsMatchContextDefined in ghc-9.10.3 · GHC.HsToCore.Monad
Constructors
EqnMatcheqn_pat :: LPat GhcTcThe first pattern of the equation
NB: The location info is used to determine whether the pattern is generated or not. This helps us avoid warnings on patterns that GHC elaborated.
NB: We have already applied
decideBangHoodto this pattern. See Note [decideBangHood] in GHC.HsToCore.Utilseqn_rest :: EquationInfoThe rest of the equation after its first pattern
EqnDone (MatchResult CoreExpr)What to do after match
Instances1Outputable
Outputable EquationInfoDefined in ghc-9.10.3 · GHC.HsToCore.Monad
This is a value of type a with potentially a CoreExpr-shaped hole in it. This is used to deal with cases where we are potentially handling pattern match failure, and want to later specify how failure is handled.
Constructors
MR_Infallible (DsM a)We represent the case where there is no hole without a function from CoreExpr, like this, because sometimes we have nothing to put in the hole and so want to be sure there is in fact no hole.
MR_Fallible (CoreExpr -> DsM a)
Instances2Functor, Applicative
Functor MatchResultDefined in ghc-9.10.3 · GHC.HsToCore.MonadApplicative MatchResultDefined in ghc-9.10.3 · GHC.HsToCore.MonadProduct is an "or" on fallibility---the combined match result is infallible only if the left and right argument match results both were.
This is useful for combining a bunch of alternatives together and then getting the overall fallibility of the entire group. See
mkDataConCasefor an example.
pprRuntimeTrace Inject a trace message into the compiled program. Whereas pprTrace prints out information *while compiling*, pprRuntimeTrace captures that information and causes it to be printed *at runtime* using Debug.Trace.trace.
pprRuntimeTrace hdr doc expr
will produce an expression that looks like
trace (hdr + doc) expr
When using this to debug a module that Debug.Trace depends on, it is necessary to import {-# SOURCE #-} Debug.Trace () in that module. We could avoid this inconvenience by wiring in Debug.Trace.trace, but that doesn't seem worth the effort and maintenance cost.