exon-0.2.0.0: Monoidal Quasiquote Interpolation
Safe HaskellNone
LanguageHaskell2010

Exon.Quote

Description

 
Synopsis

Documentation

exonError :: ToString e => MonadFail m => e -> m a Source #

class Quasi m => QOrIO (m :: Type -> Type) where Source #

Instances

Instances details
QOrIO IO Source # 
Instance details

Defined in Exon.Quote

QOrIO Q Source # 
Instance details

Defined in Exon.Quote

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|]
"one\ntwo\nthree"

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
"xyz"

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

exonws :: QuasiQuoter Source #

A variant of exon that always keeps whitespace verbatim.