Safe Haskell | Ignore |
---|---|
Language | Haskell2010 |
Synopsis
- type DsM = TcRnIf DsGblEnv DsLclEnv
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- initDs :: HscEnv -> TcGblEnv -> DsM a -> IO (Messages DsMessage, Maybe a)
- initDsTc :: DsM a -> TcM (Messages DsMessage, Maybe a)
- initTcDsForSolver :: TcM a -> DsM a
- initDsWithModGuts :: HscEnv -> ModGuts -> DsM a -> IO (Messages DsMessage, Maybe a)
- fixDs :: (a -> DsM a) -> DsM a
- foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b
- whenGOptM :: GeneralFlag -> TcRnIf gbl lcl () -> TcRnIf gbl lcl ()
- unsetGOptM :: GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- unsetWOptM :: WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
- xoptM :: Extension -> TcRnIf gbl lcl Bool
- class Functor f => Applicative (f :: Type -> Type) where
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- duplicateLocalDs :: Id -> DsM Id
- newSysLocalDs :: Mult -> Type -> DsM Id
- newSysLocalsDs :: [Scaled Type] -> DsM [Id]
- newUniqueId :: Id -> Mult -> Type -> DsM Id
- newFailLocalDs :: Mult -> Type -> DsM Id
- newPredVarDs :: PredType -> DsM Var
- getSrcSpanDs :: DsM SrcSpan
- putSrcSpanDs :: SrcSpan -> DsM a -> DsM a
- putSrcSpanDsA :: SrcSpanAnn' ann -> DsM a -> DsM a
- mkNamePprCtxDs :: DsM NamePprCtx
- newUnique :: TcRnIf gbl lcl Unique
- data UniqSupply
- newUniqueSupply :: TcRnIf gbl lcl UniqSupply
- getGhcModeDs :: DsM GhcMode
- dsGetFamInstEnvs :: DsM FamInstEnvs
- dsLookupGlobal :: Name -> DsM TyThing
- dsLookupGlobalId :: Name -> DsM Id
- dsLookupTyCon :: Name -> DsM TyCon
- dsLookupDataCon :: Name -> DsM DataCon
- dsLookupConLike :: Name -> DsM ConLike
- getCCIndexDsM :: FastString -> DsM CostCentreIndex
- type DsMetaEnv = NameEnv DsMetaVal
- data DsMetaVal
- dsGetMetaEnv :: DsM (NameEnv DsMetaVal)
- dsLookupMetaEnv :: Name -> DsM (Maybe DsMetaVal)
- dsExtendMetaEnv :: DsMetaEnv -> DsM a -> DsM a
- getPmNablas :: DsM Nablas
- updPmNablas :: Nablas -> DsM a -> DsM a
- addUnspecables :: Set EvId -> DsM a -> DsM a
- getUnspecables :: DsM (Set EvId)
- dsGetCompleteMatches :: DsM CompleteMatches
- type DsWarning = (SrcSpan, SDoc)
- diagnosticDs :: DsMessage -> DsM ()
- errDsCoreExpr :: DsMessage -> DsM CoreExpr
- failWithDs :: DsMessage -> DsM a
- failDs :: DsM a
- discardWarningsDs :: DsM a -> DsM a
- data DsMatchContext = DsMatchContext (HsMatchContext GhcTc) SrcSpan
- data EquationInfo = EqnInfo {}
- data MatchResult a
- = MR_Infallible (DsM a)
- | MR_Fallible (CoreExpr -> DsM a)
- runMatchResult :: CoreExpr -> MatchResult a -> DsM a
- type DsWrapper = CoreExpr -> CoreExpr
- idDsWrapper :: DsWrapper
- pprRuntimeTrace :: String -> SDoc -> CoreExpr -> DsM CoreExpr
Documentation
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
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.
initTcDsForSolver :: TcM a -> DsM a Source #
foldlM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b #
Left-to-right monadic fold over the elements of a structure.
Given a structure t
with elements (a, b, ..., w, x, y)
, the result of
a fold with an operator function f
is equivalent to:
foldlM f z t = do aa <- f z a bb <- f aa b ... xx <- f ww x yy <- f xx y return yy -- Just @return z@ when the structure is empty
For a Monad m
, given two functions f1 :: a -> m b
and f2 :: b -> m c
,
their Kleisli composition (f1 >=> f2) :: a -> m c
is defined by:
(f1 >=> f2) a = f1 a >>= f2
Another way of thinking about foldlM
is that it amounts to an application
to z
of a Kleisli composition:
foldlM f z t = flip f a >=> flip f b >=> ... >=> flip f x >=> flip f y $ z
The monadic effects of foldlM
are sequenced from left to right.
If at some step the bind operator (
short-circuits (as with, e.g.,
>>=
)mzero
in a MonadPlus
), the evaluated effects will be from an initial
segment of the element sequence. If you want to evaluate the monadic
effects in right-to-left order, or perhaps be able to short-circuit after
processing a tail of the sequence of elements, you'll need to use foldrM
instead.
If the monadic effects don't short-circuit, the outermost application of
f
is to the rightmost element y
, so that, ignoring effects, the result
looks like a left fold:
((((z `f` a) `f` b) ... `f` w) `f` x) `f` y
Examples
Basic usage:
>>>
let f a e = do { print e ; return $ e : a }
>>>
foldlM f [] [0..3]
0 1 2 3 [3,2,1,0]
foldrM :: (Foldable t, Monad m) => (a -> b -> m b) -> b -> t a -> m b #
Right-to-left monadic fold over the elements of a structure.
Given a structure t
with elements (a, b, c, ..., x, y)
, the result of
a fold with an operator function f
is equivalent to:
foldrM f z t = do yy <- f y z xx <- f x yy ... bb <- f b cc aa <- f a bb return aa -- Just @return z@ when the structure is empty
For a Monad m
, given two functions f1 :: a -> m b
and f2 :: b -> m c
,
their Kleisli composition (f1 >=> f2) :: a -> m c
is defined by:
(f1 >=> f2) a = f1 a >>= f2
Another way of thinking about foldrM
is that it amounts to an application
to z
of a Kleisli composition:
foldrM f z t = f y >=> f x >=> ... >=> f b >=> f a $ z
The monadic effects of foldrM
are sequenced from right to left, and e.g.
folds of infinite lists will diverge.
If at some step the bind operator (
short-circuits (as with, e.g.,
>>=
)mzero
in a MonadPlus
), the evaluated effects will be from a tail of the
element sequence. If you want to evaluate the monadic effects in
left-to-right order, or perhaps be able to short-circuit after an initial
sequence of elements, you'll need to use foldlM
instead.
If the monadic effects don't short-circuit, the outermost application of
f
is to the leftmost element a
, so that, ignoring effects, the result
looks like a right fold:
a `f` (b `f` (c `f` (... (x `f` (y `f` z))))).
Examples
Basic usage:
>>>
let f i acc = do { print i ; return $ i : acc }
>>>
foldrM f [] [0..3]
3 2 1 0 [0,1,2,3]
unsetGOptM :: GeneralFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #
unsetWOptM :: WarningFlag -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a Source #
class Functor f => Applicative (f :: Type -> Type) where #
A functor with application, providing operations to
A minimal complete definition must include implementations of pure
and of either <*>
or liftA2
. If it defines both, then they must behave
the same as their default definitions:
(<*>
) =liftA2
id
liftA2
f x y = f<$>
x<*>
y
Further, any definition must satisfy the following:
- Identity
pure
id
<*>
v = v- Composition
pure
(.)<*>
u<*>
v<*>
w = u<*>
(v<*>
w)- Homomorphism
pure
f<*>
pure
x =pure
(f x)- Interchange
u
<*>
pure
y =pure
($
y)<*>
u
The other methods have the following default definitions, which may be overridden with equivalent specialized implementations:
As a consequence of these laws, the Functor
instance for f
will satisfy
It may be useful to note that supposing
forall x y. p (q x y) = f x . g y
it follows from the above that
liftA2
p (liftA2
q u v) =liftA2
f u .liftA2
g v
If f
is also a Monad
, it should satisfy
(which implies that pure
and <*>
satisfy the applicative functor laws).
Lift a value.
(<*>) :: f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
Example
Used in combination with (
, <$>
)(
can be used to build a record.<*>
)
>>>
data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
>>>
produceFoo :: Applicative f => f Foo
>>>
produceBar :: Applicative f => f Bar
>>>
produceBaz :: Applicative f => f Baz
>>>
mkState :: Applicative f => f MyState
>>>
mkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
liftA2 :: (a -> b -> c) -> f a -> f b -> f c #
Lift a binary function to actions.
Some functors support an implementation of liftA2
that is more
efficient than the default one. In particular, if fmap
is an
expensive operation, it is likely better to use liftA2
than to
fmap
over the structure and then use <*>
.
This became a typeclass method in 4.10.0.0. Prior to that, it was
a function defined in terms of <*>
and fmap
.
Example
>>>
liftA2 (,) (Just 3) (Just 5)
Just (3,5)
(*>) :: f a -> f b -> f b infixl 4 #
Sequence actions, discarding the value of the first argument.
Examples
If used in conjunction with the Applicative instance for Maybe
,
you can chain Maybe computations, with a possible "early return"
in case of Nothing
.
>>>
Just 2 *> Just 3
Just 3
>>>
Nothing *> Just 3
Nothing
Of course a more interesting use case would be to have effectful computations instead of just returning pure values.
>>>
import Data.Char
>>>
import Text.ParserCombinators.ReadP
>>>
let p = string "my name is " *> munch1 isAlpha <* eof
>>>
readP_to_S p "my name is Simon"
[("Simon","")]
(<*) :: f a -> f b -> f a infixl 4 #
Sequence actions, discarding the value of the second argument.
Instances
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an
Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
putSrcSpanDsA :: SrcSpanAnn' ann -> DsM a -> DsM a Source #
data UniqSupply #
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.
newUniqueSupply :: TcRnIf gbl lcl UniqSupply Source #
getCCIndexDsM :: FastString -> DsM CostCentreIndex Source #
See getCCIndexM
.
getPmNablas :: DsM Nablas Source #
Get the current pattern match oracle state. See dsl_nablas
.
updPmNablas :: Nablas -> DsM a -> DsM a Source #
Set the pattern match oracle state within the scope of the given action.
See dsl_nablas
.
dsGetCompleteMatches :: DsM CompleteMatches Source #
The COMPLETE
pragmas that are in scope.
diagnosticDs :: DsMessage -> DsM () Source #
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 Error
.
errDsCoreExpr :: DsMessage -> DsM CoreExpr Source #
Issue an error, but return the expression for (), so that we can continue reporting errors.
failWithDs :: DsMessage -> DsM a Source #
discardWarningsDs :: DsM a -> DsM a Source #
data DsMatchContext Source #
Instances
Outputable DsMatchContext Source # | |
Defined in GHC.HsToCore.Monad ppr :: DsMatchContext -> SDoc # |
data EquationInfo Source #
EqnInfo | |
|
Instances
Outputable EquationInfo Source # | |
Defined in GHC.HsToCore.Monad ppr :: EquationInfo -> SDoc # |
data MatchResult a Source #
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.
MR_Infallible (DsM a) | We represent the case where there is no hole without a function from
|
MR_Fallible (CoreExpr -> DsM a) |
Instances
Applicative MatchResult Source # | Product 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 |
Defined in GHC.HsToCore.Monad pure :: a -> MatchResult a # (<*>) :: MatchResult (a -> b) -> MatchResult a -> MatchResult b # liftA2 :: (a -> b -> c) -> MatchResult a -> MatchResult b -> MatchResult c # (*>) :: MatchResult a -> MatchResult b -> MatchResult b # (<*) :: MatchResult a -> MatchResult b -> MatchResult a # | |
Functor MatchResult Source # | |
Defined in GHC.HsToCore.Monad fmap :: (a -> b) -> MatchResult a -> MatchResult b # (<$) :: a -> MatchResult b -> MatchResult a # |
runMatchResult :: CoreExpr -> MatchResult a -> DsM a Source #
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.