ascii-th-1.2.0.1: Template Haskell support for ASCII
Safe HaskellSafe-Inferred
LanguageGHC2021

ASCII.QuasiQuoters

Description

Use of these quasi-quoters in a pattern context requires the ViewPatterns language extension.

Synopsis

Character

char :: QuasiQuoter Source #

An expression pattern corresponding to an ASCII character

In an expression context

The result will have a FromChar constraint.

The quasi-quoted string must consist of a single character that is within the ASCII character set.

[char|e|] == SmallLetterE

[char|e|] == (101 :: Word8)

Since this is polymorphic, a type signature is recommended.

In a pattern context

The pattern matches a value of a type satisfying the ToChar constraint.

let
    x = case Tilde of
          [char|@|] -> 1
          [char|~|] -> 2
          _ -> 3
in
    x == 2

String

string :: QuasiQuoter Source #

An expression or pattern corresponding to an ASCII string

In an expression context

The result will have a FromString constraint.

The quasi-quoted string must consist only of characters are within the ASCII character set.

[string|Hello!|] ==
    [CapitalLetterH,SmallLetterE,SmallLetterL,SmallLetterL,SmallLetterO,ExclamationMark]

[string|Hello!|] == ("Hello!" :: String)

[string|Hello!|] == ("Hello!" :: Text)

toLazyByteString [string|Hello!|] == "Hello!"

Since this is polymorphic, a type signature is recommended.

In a pattern context

The pattern matches a value of a type satisfying the ToString constraint.

let
    x = case [CapitalLetterH, SmallLetterI] of
          [string|Bye|] -> 1
          [string|Hi|] -> 2
          _ -> 3
in
    x == 2

Caseless string

caseless :: QuasiQuoter Source #

An expression or pattern corresponding to a case-insensitive ASCII string

In an expression context

A monomorphic expression of type [CaselessChar].

[caseless|Hello!|] ==
    [LetterH, LetterE, LetterL, LetterL, LetterO, ExclamationMark]

In a pattern context

A case-insensitive match of any type belonging to the ToCaselessString class.

let
    x = case "Hello!" :: Text of
          [caseless|Bye!|] -> 1
          [caseless|hEllo!|] -> 2
          _ -> 3
in
    x == 2

Upper-case string

upper :: QuasiQuoter Source #

An expression or pattern corresponding to an ASCII string where all the letters are of upper case

The letters in the body of the quasi-quotation may be written in any case you like; they will be converted to upper case automatically.

In an expression context

The expression can become any type satisfying the (ToCasefulString 'UpperCase) constraint. Any letters in the quoted content will be converted to upper case.

[upper|Hello!|] == ("HELLO!" :: Text)

[upper|Hello!|] == ("HELLO!" :: ASCII'upper ByteString)

In a pattern context

The pattern matches a value of a type satisfying the ToString constraint. A value matches this pattern if:

  • All of the letters in the tested value are in upper case
  • The tested value satisfies a case-insensitive comparison with the quasi-quoted content
let
    x = case "HI!" :: Text of
          [QQ.upper|wow|] -> 1
          [QQ.upper|Hi!|] -> 2
          _ -> 3
in
    x == 2

Lower-case string

lower :: QuasiQuoter Source #

An expression or pattern corresponding to an ASCII string where all the letters are of lower case

The letters in the body of the quasi-quotation may be written in any case you like; they will be converted to lower case automatically.

In an expression context

The expression can become any type satisfying the (ToCasefulString 'LowerCase) constraint. Any letters in the quoted content will be converted to lower case.

[lower|Hello!|] == ("hello!" :: Text)

[lower|Hello!|] == ("hello!" :: ASCII'lower ByteString)

In a pattern context

The pattern matches a value of a type satisfying the ToString constraint. A value matches this pattern if:

  • All of the letters in the tested value are in lower case
  • The tested value satisfies a case-insensitive comparison with the quasi-quoted content
let
    x = case "hi!" :: Text of
          [lower|wow|] -> 1
          [lower|Hi!|] -> 2
          _ -> 3
in
    x == 2