ContentsIndex
TypeCheck
Contents
Types
State of the Typechecker
Checking the Goal (Clause head)
Checking FullRules
Checking SimpleRules
Main Routines.
Type Errors
Utilities
Synopsis
data Type
= TypeLabel
| TypeTerm
data Def
= Defined
| Defining
data TypeEnv = TypeEnv {
tyDef :: !(Map Variable (Type, Def))
arity :: !(Map Head Int)
}
type TypeSt = StateT TypeEnv TypeCheckResult
forgetVariables :: TypeSt ()
fixVariables :: TypeSt ()
checkHead :: Head -> Int -> TypeSt ()
checkVar :: Variable -> Type -> TypeSt ()
definingVar :: Variable -> TypeSt ()
useVar :: Variable -> TypeSt ()
checkGoalTerm :: Term -> TypeSt ()
checkGoal :: Clause -> TypeSt ()
checkToplevelPattern :: Term -> TypeSt ()
checkInnerPattern :: Term -> Term -> TypeSt ()
checkClause :: Clause -> TypeSt ()
checkFullRule :: Rule -> TypeSt ()
checkSimplePattern :: Term -> TypeSt ()
checkSimpleRule :: Rule -> TypeSt ()
typeCheckRules :: [Rule] -> [Rule] -> TypeSt ()
typeCheckGrammar :: [(Label, [Term])] -> TypeSt ()
typeCheckRulesAndGrammar :: [Rule] -> [Rule] -> [(Label, [Term])] -> Maybe (Rule, TypeError)
data TypeError
= TermTooDeep Term
| LabelRequired Variable
| MultipleArity Head Int Int
| MultipleDef Variable
| NoDef Variable
data TypeCheckResult a
= TypeCheck a
| TypeError Rule TypeError
typeErrorMsg :: Rule -> TypeError -> String
typeError :: TypeError -> TypeSt ()
setRuleOnError :: Rule -> TypeSt a -> TypeSt a
setProductionOnError :: Label -> Term -> TypeSt a -> TypeSt a
Types
data Type
The type of a variable (with 'absint' ordering).
Constructors
TypeLabelA variable that will be bound to labels, only.
TypeTermA variable that can be bound to any term.
Instances
Eq Type
Ord Type
data Def
While pattern matching, the definition state of a variable. Used to spot doubly defined variables ( malformed patterns as f(X,X) ).
Constructors
DefinedVariable was defined by an earlier match.
DefiningVariable was defined by the current match.
data TypeEnv
The state holding all the information about variables and term heads.
Constructors
TypeEnv
tyDef :: !(Map Variable (Type, Def))Type and definition of variables.
arity :: !(Map Head Int)Arity of term heads.
State of the Typechecker
type TypeSt = StateT TypeEnv TypeCheckResult
The actual state monad. Represents a computation having a TypeEnv as a state, but that can fail with a TypeError.
forgetVariables :: TypeSt ()
Forget all about variables (but remember term heads information)
fixVariables :: TypeSt ()
Make Defining variables become Defined.
checkHead :: Head -> Int -> TypeSt ()

Check a term Head.

  • If already known, but the arity disagrees, fail.
  • Otherwise, remember the arity.
checkVar :: Variable -> Type -> TypeSt ()

Check a Variable occurring in a pattern.

  • If already known, but is not Defined or the type does not match, fail.
  • Otherwise, mark it as Defining and remember the type.
definingVar :: Variable -> TypeSt ()
Define a Variable using TypeTerm and Defining. Do not perform any check.
useVar :: Variable -> TypeSt ()
If a variable is not Defined, fail.
Checking the Goal (Clause head)
checkGoalTerm :: Term -> TypeSt ()
Check the goal Term.
checkGoal :: Clause -> TypeSt ()
Check a goal.
Checking FullRules
checkToplevelPattern :: Term -> TypeSt ()
Check the toplevel pattern of a FullRule.
checkInnerPattern :: Term -> Term -> TypeSt ()
Check a pattern that was inside a f(-) context in a FullRule.
checkClause :: Clause -> TypeSt ()
Check a FullRule Clause.
checkFullRule :: Rule -> TypeSt ()
Checking SimpleRules
checkSimplePattern :: Term -> TypeSt ()
Check the pattern inside a SimpleRule.
checkSimpleRule :: Rule -> TypeSt ()
Check a SimpleRule for arity consistency, and undefined variables.
Main Routines.
typeCheckRules :: [Rule] -> [Rule] -> TypeSt ()
Check SimpleRules and FullRules,
typeCheckGrammar :: [(Label, [Term])] -> TypeSt ()
Check for arity consistency.
typeCheckRulesAndGrammar :: [Rule] -> [Rule] -> [(Label, [Term])] -> Maybe (Rule, TypeError)
The main type checking routine. Return Nothing on success. On error, the Rule premiss is empty iff the error was in the grammar.
Type Errors
data TypeError
Constructors
TermTooDeep TermMaximum term depth is one in FullRules.
LabelRequired VariableA label or a label-valued variable was expected.
MultipleArity Head Int IntTerm head with two distinct arities found.
MultipleDef VariableA pattern defined a variable more than once.
NoDef VariableA variable occurs only in the goal.
data TypeCheckResult a
A simple error monad that propagates errors.
Constructors
TypeCheck aType check succeded.
TypeError Rule TypeErrorType check failed for a rule.
Instances
Monad TypeCheckResult
typeErrorMsg :: Rule -> TypeError -> String
User-friendly error messages.
Utilities
typeError :: TypeError -> TypeSt ()
Smart constructor.
setRuleOnError :: Rule -> TypeSt a -> TypeSt a
setProductionOnError :: Label -> Term -> TypeSt a -> TypeSt a
Produced by Haddock version 0.6