hssqlppp-0.0.10: Sql parser and type checkerSource codeContentsIndex
Data types
bits and pieces
Environment values
operator utils

This module contains the environment data types and a helper functions. You almost certainly will never have to do anything with Environments apart from read them from a database to supply to the annotation function. If you only need to type check against the default template1 catalog, then you don't even need to do this - is you use the annotation function with no Environment parameter, it uses the default template1 catalog.

The environment data type serves the following purposes:

  • Contains all the catalog information needed to type check against an existing database.
  • A copy of the catalog information from a default template1 database is included - defaultTemplate1Environment, at some point this might be used to allow typechecking sql code against this catalog without having an available PostGreSQL install.
  • It is used internally to keep track of updates to the catalog whilst running an annotation process (e.g. so that a select can type check against a create table given in the same source). It is also used to track other identifier types, such as attribute references in select expressions, and argument and variable types inside create function statements.

You can see what kind of stuff is contained in the Environment type by looking at the EnvironmentUpdate type.

data Environment
data EnvironmentUpdate
= EnvCreateScalar Type String Bool
| EnvCreateDomain Type Type
| EnvCreateComposite String [(String, Type)]
| EnvCreateCast Type Type CastContext
| EnvCreateTable String [(String, Type)] [(String, Type)]
| EnvCreateView String [(String, Type)]
| EnvCreateFunction FunFlav String [Type] Type
| EnvStackIDs [QualifiedIDs]
| EnvSetStarExpansion [QualifiedIDs]
type QualifiedIDs = (String, [(String, Type)])
data CastContext
= ImplicitCastContext
| AssignmentCastContext
| ExplicitCastContext
data CompositeFlavour
= Composite
| TableComposite
| ViewComposite
type CompositeDef = (String, CompositeFlavour, Type, Type)
type FunctionPrototype = (String, [Type], Type)
type DomainDefinition = (Type, Type)
data FunFlav
= FunPrefix
| FunPostfix
| FunBinary
| FunName
| FunAgg
emptyEnvironment :: Environment
defaultEnvironment :: Environment
defaultTemplate1Environment :: Environment
readEnvironmentFromDatabase :: String -> IO [EnvironmentUpdate]
updateEnvironment :: Environment -> [EnvironmentUpdate] -> Either [TypeError] Environment
data OperatorType
= BinaryOp
| PrefixOp
| PostfixOp
getOperatorType :: Environment -> String -> OperatorType
isOperatorName :: String -> Bool
Data types
data Environment Source
The main datatype, this holds the catalog and context information to type check against.
data EnvironmentUpdate Source
EnvCreateScalar Type String Booladd a new scalar type with the name given, also creates an array type automatically
EnvCreateDomain Type Type
EnvCreateComposite String [(String, Type)]
EnvCreateCast Type Type CastContext
EnvCreateTable String [(String, Type)] [(String, Type)]
EnvCreateView String [(String, Type)]
EnvCreateFunction FunFlav String [Type] Type
EnvStackIDs [QualifiedIDs]to allow an unqualified identifier reference to work you need to supply an extra entry with "" as the alias, and all the fields, in the case of joins, these unaliased fields need to have the duplicates removed and the types resolved
EnvSetStarExpansion [QualifiedIDs]to allow an unqualified star to work you need to supply an extra entry with "" as the alias, and all the fields
show/hide Instances
bits and pieces
type QualifiedIDs = (String, [(String, Type)])Source
Represents the types of the ids available, currently used for resolving identifiers inside select expressions. Will probably change as this is fixed to support more general contexts. The components represent the qualifying name (empty string for no qualifying name), the list of identifier names with their types, and the list of system column identifier names with their types.
data CastContext Source
Use to note what the flavour of a cast is, i.e. if/when it can be used implicitly.
show/hide Instances
data CompositeFlavour Source
Used to distinguish between standalone composite types, and automatically generated ones, generated from a table or view respectively.
show/hide Instances
type CompositeDef = (String, CompositeFlavour, Type, Type)Source
Provides the definition of a composite type. The components are composite (or table or view) name, the flavour of the composite, the types of the composite attributes, and the types of the system columns iff the composite represents a table type (the third and fourth components are always UnnamedCompositeTypes).
type FunctionPrototype = (String, [Type], Type)Source
The components are: function (or operator) name, argument types, and return type.
type DomainDefinition = (Type, Type)Source
The components are domain type, base type (todo: add check constraint).
data FunFlav Source
show/hide Instances
Environment values
emptyEnvironment :: EnvironmentSource
Represents an empty environment. This doesn't contain things like the 'and' operator, and so if you try to use it it will almost certainly not work.
defaultEnvironment :: EnvironmentSource
Represents what you probably want to use as a starting point if you are building an environment from scratch. It contains information on built in function like things that aren't in the PostGreSQL catalog, such as greatest, coalesce, keyword operators like 'and', etc..
defaultTemplate1Environment :: EnvironmentSource
:: Stringname of the database to read
-> IO [EnvironmentUpdate]

Creates an EnvironmentUpdate list by reading the database given. To create an Environment value from this, use

 env <- readEnvironmentFromDatabase something
 let newEnv = updateEnvironment defaultEnvironment env
updateEnvironment :: Environment -> [EnvironmentUpdate] -> Either [TypeError] EnvironmentSource
Applies a list of EnvironmentUpdates to an Environment value to produce a new Environment value.
operator utils
data OperatorType Source
show/hide Instances
getOperatorType :: Environment -> String -> OperatorTypeSource
isOperatorName :: String -> BoolSource
Produced by Haddock version 2.6.0