exon- Monoidal Quasiquote Interpolation
Safe HaskellSafe-Inferred





exonWith :: Q Type -> QuasiQuoter Source #

Constructor for a quasiquoter for an arbitrary tag.

This can be used to define quoters with custom logic, requiring an instance of Exon for the given type:

>>> import Exon.Class.Exon (Exon(..))
>>> import Exon.Data.Segment (Segment(String))
>>> data Nl
>>> instance (Monoid a, IsString a) => Exon Nl a where insertWhitespace s1 _ s2 = appendSegment @Nl (appendSegment @Nl s1 (String "\n")) s2
>>> exonnl = exonWith [t|Nl|]
>>> [exonnl|one   two     three|]


exon :: QuasiQuoter Source #

A quasiquoter that allows interpolation, concatenating the resulting segments monoidally.

>>> [exon|write #{show @Text (5 :: Int)} lines of code|] :: Text
"write 5 lines of code"

The default implementation for any non-stringly type uses IsString to construct the literal segments and mappend to combine them, ignoring whitespace segments.

>>> newtype Part = Part Text deriving newtype (Show, Semigroup, Monoid, IsString)
>>> [exon|x #{Part "y"}z|] :: Part

This behavior can be customized by writing an instance of Exon.

exonws :: QuasiQuoter Source #

A variant of exon that always keeps whitespace verbatim.