Q package:ghc-internal
In short,
Q provides the
Quasi operations in one neat
monad for the user.
The longer story, is that
Q wraps an arbitrary
Quasi-able monad. The perceptive reader notices that
Quasi has only two instances,
Q itself and
IO,
neither of which have concrete implementations.
Q plays the
trick of
dependency inversion, providing an abstract interface
for the user which is later concretely fufilled by an concrete
Quasi instance, internal to GHC.
Template Haskell supports quasiquoting, which permits users to
construct program fragments by directly writing concrete syntax. A
quasiquoter is essentially a function with takes a string to a
Template Haskell AST. This module defines the
QuasiQuoter
datatype, which specifies a quasiquoter
q which can be
invoked using the syntax
[q| ... string to parse ... |] when
the
QuasiQuotes language extension is enabled, and some
utility functions for manipulating quasiquoters. Nota bene: this
package does not define any parsers, that is up to you.
This is an internal module. Please import
Quote instead.
The
QuasiQuoter type, a value
q of this type can be
used in the syntax
[q| ... string to parse ...|]. In fact,
for convenience, a
QuasiQuoter actually defines multiple
quasiquoters to be used in different splice contexts; if you are only
interested in defining a quasiquoter to be used for expressions, you
would define a
QuasiQuoter with only
quoteExp, and leave
the other fields stubbed out with errors.
The
Quote class implements the minimal interface which is
necessary for desugaring quotations.
- The Monad m superclass is needed to stitch together the
different AST fragments.
- newName is used when desugaring binding structures such as
lambdas to generate fresh names.
Therefore the type of an untyped quotation in GHC is `Quote m => m
Exp`
For many years the type of a quotation was fixed to be `Q Exp` but by
more precisely specifying the minimal interface it enables the
Exp to be extracted purely from the quotation without
interacting with
Q.
Used to implement
quot for the
Integral typeclass. This
performs integer division on its two parameters, truncated towards
zero.
Example
>>> quotInt 10 2
5
>>> quot 10 2
5
Rounds towards zero. The behavior is undefined if the second argument
is zero.
Rounds towards zero element-wise.
Rounds towards zero element-wise.
Rounds towards zero element-wise.
Rounds towards zero element-wise.
Rounds towards zero element-wise.
Rounds towards zero element-wise.
Rounds towards zero element-wise.
Rounds towards zero element-wise.
Rounds towards zero element-wise.