interpolatedstring-qq2-0.1.0.0: QuasiQuoter for multi-line interpolated strings

Safe HaskellNone
LanguageHaskell2010

Text.InterpolatedString.QQ2

Description

QuasiQuoter for interpolated strings using Perl 6 syntax.

The q form does one thing and does it well: It contains a multi-line string with no interpolation at all:

{-# LANGUAGE QuasiQuotes, ExtendedDefaultRules #-}
import Text.InterpolatedString.QQ2 (q)
foo :: String -- Text, ByteString etc also works
foo = [q|

Well here is a
    multi-line string!

|]

Any instance of the IsString class is permitted.

The qc form interpolates curly braces: expressions inside #{} will be directly interpolated if it's a Char, String, Text or ByteString, or it will have show called if it is not.

Escaping of '{' is done with backslash.

For interpolating numeric expressions without an explicit type signature, use the ExtendedDefaultRules lanuage pragma, as shown below:

{-# LANGUAGE QuasiQuotes, ExtendedDefaultRules #-}
import Text.InterpolatedString.QQ2 (qc)
bar :: String
bar = [qc| Well {6 * 7} |]

bar will have the value " Well hello there 42 ".

If you want control over how show works on your types, define a custom ShowQ instance:

For example, this instance allows you to display interpolated lists of strings as a sequence of words, removing those pesky brackets, quotes, and escape sequences.

{-# LANGUAGE FlexibleInstances #-}
import Text.InterpolatedString.QQ2 (qc, ShowQ(..))
instance ShowQ [String] where
    showQ = unwords

qc permits output to any types with both IsString and Monoid instances.

{--}
import Text.InterpolatedString.QQ2 (qc)
import Data.Text (Text)
import Data.ByteString.Char8 (ByteString)
qux :: ByteString
qux = [qc| This will convert {"ByteString" :: ByteString} |]
Synopsis

Documentation

qc :: QuasiQuoter Source #

QuasiQuoter for interpolating '{expr}' into a string literal. The pattern portion is undefined.

q :: QuasiQuoter Source #

QuasiQuoter for a non-interpolating string literal. The pattern portion is undefined.

class ShowQ a where Source #

A class for types that use special interpolation rules. Instances of ShowQ that are also instances of IsString should obey the following law:

fromString (showQ s) == s

because this library relies on this fact to optimize away needless string conversions.

Methods

showQ :: a -> String Source #

Instances
ShowQ Char Source # 
Instance details

Defined in Text.InterpolatedString.QQ2

Methods

showQ :: Char -> String Source #

Show a => ShowQ a Source # 
Instance details

Defined in Text.InterpolatedString.QQ2

Methods

showQ :: a -> String Source #

ShowQ String Source # 
Instance details

Defined in Text.InterpolatedString.QQ2

Methods

showQ :: String -> String Source #

ShowQ ByteString Source # 
Instance details

Defined in Text.InterpolatedString.QQ2

ShowQ ByteString Source # 
Instance details

Defined in Text.InterpolatedString.QQ2

ShowQ Text Source # 
Instance details

Defined in Text.InterpolatedString.QQ2

Methods

showQ :: Text -> String Source #

ShowQ Text Source # 
Instance details

Defined in Text.InterpolatedString.QQ2

Methods

showQ :: Text -> String Source #