The Quipper System

Safe HaskellNone

Libraries.Template.LiftQ

Contents

Description

This module defines the state monad used in Lifting for Template-Haskell term manipulation.

Synopsis

Documentation

data LiftState Source

State of the monad.

Constructors

LiftState 

Fields

boundVar :: Map Name Int

How many times each name is bound.

prefix :: Maybe String

The template prefix .

monadName :: Maybe String

The name of the monad.

emptyLiftState :: LiftStateSource

An empty state.

type LiftQState = StateT LiftState ErrMsgQSource

Shortcut to StateT LiftState ErrMsgQ.

data LiftQ a Source

The monad.

Constructors

LiftQ (LiftQState a) 

Instances

getState :: LiftQ LiftStateSource

Retrieve the state from the monad.

setState :: LiftState -> LiftQ ()Source

Set the state of the monad.

Various functions to go back and forth between monads.

embedQ :: Q a -> LiftQ aSource

From Q to LiftQ.

extractQ :: String -> LiftQ a -> Q aSource

Get Q out of LiftQ

errorMsg :: String -> LiftQ aSource

Set an error message.

Working with variable names.

addToBoundVar :: Name -> LiftQ ()Source

Increase the number of binds of a variable name.

removeFromBoundVar :: Name -> LiftQ ()Source

Decrease the number of binds of a variable name.

withBoundVar :: Name -> LiftQ a -> LiftQ aSource

Run a computation with a particular name being bound.

withBoundVars :: [Name] -> LiftQ a -> LiftQ aSource

Run a computation with a particular list of names being bound.

isBoundVar :: Name -> LiftQ BoolSource

Say whether a given name is bound.

Other operations on monad state.

setPrefix :: String -> LiftQ ()Source

Set the template prefix.

getPrefix :: LiftQ StringSource

Get the template prefix.

setMonadName :: String -> LiftQ ()Source

Set the monad name.

getMonadName :: LiftQ StringSource

Get the monad name.

Functions dealing with variable names.

mkName :: String -> NameSource

Make a name out of a string.

newName :: String -> LiftQ NameSource

Make a name out of a string, monadic-style.

sanitizeString :: String -> StringSource

Make any string into a string containing only [0-9a-zA-Z_.]. For example, it replaces any occurrence of "+" with "symb_plus_".

templateString :: String -> LiftQ StringSource

Take a string and make it into a valid Haskell name starting with "template_".

lookForTemplate :: Name -> LiftQ (Maybe Name)Source

Look for the corresponding template name.

makeTemplateName :: Name -> LiftQ NameSource

Make a the template version of a given name.

Other functions.

prettyPrint :: Ppr a => LiftQ a -> IO ()Source

Print on the terminal a monadic, printable object.

clauseGetPats :: Clause -> [Pat]Source

Project patterns out of a clause.

equalNEListElts :: Eq a => [a] -> BoolSource

Check that the list is a non-empty repetition of the same element.

clausesLengthPats :: [Clause] -> LiftQ IntSource

Returns the length of the patterns in a list of clauses. Throw an error if the patterns do not have all the same size.