Agda-2.5.2: A dependently typed functional programming language and proof assistant

Safe Haskell | None
Language | Haskell2010

Agda.Syntax.Concrete.Definitions

Description

Preprocess `Declaration`s, producing `NiceDeclaration`s.

- Attach fixity and syntax declarations to the definition they refer to.
- Distribute the following attributes to the individual definitions: `abstract`, `instance`, `postulate`, `primitive`, `private`, termination pragmas.
- Gather the function clauses belonging to one function definition.
- Expand ellipsis `...` in function clauses following `with`.
- Infer mutual blocks. A block starts when a lone signature is encountered, and ends when all lone signatures have seen their definition.
- Report basic well-formedness error, when one of the above transformation fails.

Synopsis

- data NiceDeclaration
  - = Axiom Range Fixity' Access IsAbstract IsInstance ArgInfo (Maybe [Occurrence]) Name Expr
  - | NiceField Range Fixity' Access IsAbstract IsInstance Name (Arg Expr)
  - | PrimitiveFunction Range Fixity' Access IsAbstract Name Expr
  - | NiceMutual Range TerminationCheck PositivityCheck [NiceDeclaration]
  - | NiceModule Range Access IsAbstract QName Telescope [Declaration]
  - | NiceModuleMacro Range Access Name ModuleApplication OpenShortHand ImportDirective
  - | NiceOpen Range QName ImportDirective
  - | NiceImport Range QName (Maybe AsName) OpenShortHand ImportDirective
  - | NicePragma Range Pragma
  - | NiceRecSig Range Fixity' Access IsAbstract PositivityCheck Name [LamBinding] Expr
  - | NiceDataSig Range Fixity' Access IsAbstract PositivityCheck Name [LamBinding] Expr
  - | NiceFunClause Range Access IsAbstract TerminationCheck Catchall Declaration
  - | FunSig Range Fixity' Access IsAbstract IsInstance IsMacro ArgInfo TerminationCheck Name Expr
  - | FunDef Range [Declaration] Fixity' IsAbstract TerminationCheck Name [Clause]
  - | DataDef Range Fixity' IsAbstract PositivityCheck Name [LamBinding] [NiceConstructor]
  - | RecDef Range Fixity' IsAbstract PositivityCheck Name (Maybe (Ranged Induction)) (Maybe Bool) (Maybe (ThingWithFixity Name, IsInstance)) [LamBinding] [NiceDeclaration]
  - | NicePatternSyn Range Fixity' Name [Arg Name] Pattern
  - | NiceUnquoteDecl Range [Fixity'] Access IsAbstract IsInstance TerminationCheck [Name] Expr
  - | NiceUnquoteDef Range [Fixity'] Access IsAbstract TerminationCheck [Name] Expr
- type NiceConstructor = NiceTypeSignature
- type NiceTypeSignature = NiceDeclaration
- data Clause = Clause Name Catchall LHS RHS WhereClause [Clause]
- data DeclarationException
  - = MultipleFixityDecls [(Name, [Fixity'])]
  - | MultiplePolarityPragmas [Name]
  - | InvalidName Name
  - | DuplicateDefinition Name
  - | MissingDefinition Name
  - | MissingWithClauses Name
  - | MissingTypeSignature LHS
  - | MissingDataSignature Name
  - | WrongDefinition Name DataRecOrFun DataRecOrFun
  - | WrongParameters Name
  - | NotAllowedInMutual NiceDeclaration
  - | UnknownNamesInFixityDecl [Name]
  - | UnknownNamesInPolarityPragmas [Name]
  - | PolarityPragmasButNotPostulates [Name]
  - | Codata Range
  - | DeclarationPanic String
  - | UselessPrivate Range
  - | UselessAbstract Range
  - | UselessInstance Range
  - | WrongContentBlock KindOfBlock Range
  - | AmbiguousFunClauses LHS [Name]
  - | InvalidTerminationCheckPragma Range
  - | InvalidMeasureMutual Range
  - | PragmaNoTerminationCheck Range
  - | InvalidCatchallPragma Range
  - | UnquoteDefRequiresSignature [Name]
  - | BadMacroDef NiceDeclaration
  - | InvalidNoPositivityCheckPragma Range
- type Nice = StateT NiceEnv (Either DeclarationException)
- runNice :: Nice a -> Either DeclarationException a
- niceDeclarations :: [Declaration] -> Nice [NiceDeclaration]
- notSoNiceDeclarations :: NiceDeclaration -> [Declaration]
- niceHasAbstract :: NiceDeclaration -> Maybe IsAbstract
- type Measure = Name

# Documentation

data NiceDeclaration #

The nice declarations. No fixity declarations and function definitions are contained in a single constructor instead of spread out between type signatures and clauses. The `private`, `postulate`, `abstract` and `instance` modifiers have been distributed to the individual declarations.

Observe the order of components:

Range Fixity' Access IsAbstract IsInstance TerminationCheck PositivityCheck

further attributes

(Q)Name

content (Expr, Declaration ...)

Constructors

Axiom Range Fixity' Access IsAbstract IsInstance ArgInfo (Maybe [Occurrence]) Name Expr | `IsAbstract` argument: We record whether a declaration was made in an `abstract` block. `ArgInfo` argument: Axioms and functions can be declared irrelevant. (`Hiding` should be `NotHidden`.) `Maybe [Occurrence]` argument: Polarities can be assigned to identifiers.
NiceField Range Fixity' Access IsAbstract IsInstance Name (Arg Expr) |
PrimitiveFunction Range Fixity' Access IsAbstract Name Expr |
NiceMutual Range TerminationCheck PositivityCheck [NiceDeclaration] |
NiceModule Range Access IsAbstract QName Telescope [Declaration] |
NiceModuleMacro Range Access Name ModuleApplication OpenShortHand ImportDirective |
NiceOpen Range QName ImportDirective |
NiceImport Range QName (Maybe AsName) OpenShortHand ImportDirective |
NicePragma Range Pragma |
NiceRecSig Range Fixity' Access IsAbstract PositivityCheck Name [LamBinding] Expr |
NiceDataSig Range Fixity' Access IsAbstract PositivityCheck Name [LamBinding] Expr |
NiceFunClause Range Access IsAbstract TerminationCheck Catchall Declaration | An uncategorized function clause, could be a function clause without type signature or a pattern lhs (e.g. for irrefutable let). The `Declaration` is the actual `FunClause`.
FunSig Range Fixity' Access IsAbstract IsInstance IsMacro ArgInfo TerminationCheck Name Expr |
FunDef Range [Declaration] Fixity' IsAbstract TerminationCheck Name [Clause] | Block of function clauses (we have seen the type signature before). The `Declaration`s are the original declarations that were processed into this `FunDef` and are only used in `notSoNiceDeclaration`.
DataDef Range Fixity' IsAbstract PositivityCheck Name [LamBinding] [NiceConstructor] |
RecDef Range Fixity' IsAbstract PositivityCheck Name (Maybe (Ranged Induction)) (Maybe Bool) (Maybe (ThingWithFixity Name, IsInstance)) [LamBinding] [NiceDeclaration] |
NicePatternSyn Range Fixity' Name [Arg Name] Pattern |
NiceUnquoteDecl Range [Fixity'] Access IsAbstract IsInstance TerminationCheck [Name] Expr |
NiceUnquoteDef Range [Fixity'] Access IsAbstract TerminationCheck [Name] Expr |

Instances

Show NiceDeclaration # |
Methods showsPrec :: Int -> NiceDeclaration -> ShowS # show :: NiceDeclaration -> String # showList :: [NiceDeclaration] -> ShowS #
HasRange NiceDeclaration # |
Methods getRange :: NiceDeclaration -> Range #
ToAbstract NiceDeclaration Declaration # |
Methods toAbstract :: NiceDeclaration -> ScopeM Declaration #

type NiceConstructor = NiceTypeSignature #

Only `Axiom`s.

type NiceTypeSignature = NiceDeclaration #

Only `Axiom`s.

data Clause #

One clause in a function definition. There is no guarantee that the `LHS` actually declares the `Name`. We will have to check that later.

Constructors

Clause Name Catchall LHS RHS WhereClause [Clause] |

Instances

Show Clause # |
Methods showsPrec :: Int -> Clause -> ShowS # show :: Clause -> String # showList :: [Clause] -> ShowS #
ToAbstract Clause Clause # |
Methods toAbstract :: Clause -> ScopeM Clause #

data DeclarationException #

The exception type.

Constructors

MultipleFixityDecls [(Name, [Fixity'])] |
MultiplePolarityPragmas [Name] |
InvalidName Name |
DuplicateDefinition Name |
MissingDefinition Name |
MissingWithClauses Name |
MissingTypeSignature LHS |
MissingDataSignature Name |
WrongDefinition Name DataRecOrFun DataRecOrFun |
WrongParameters Name |
NotAllowedInMutual NiceDeclaration |
UnknownNamesInFixityDecl [Name] |
UnknownNamesInPolarityPragmas [Name] |
PolarityPragmasButNotPostulates [Name] |
Codata Range |
DeclarationPanic String |
UselessPrivate Range |
UselessAbstract Range |
UselessInstance Range |
WrongContentBlock KindOfBlock Range |
AmbiguousFunClauses LHS [Name] | in a mutual block, a clause could belong to any of the `[Name]` type signatures
InvalidTerminationCheckPragma Range |
InvalidMeasureMutual Range | In a mutual block, all or none need a MEASURE pragma. Range is of mutual block.
PragmaNoTerminationCheck Range | Pragma `{--}` has been replaced by {--} and {--}.
InvalidCatchallPragma Range |
UnquoteDefRequiresSignature [Name] |
BadMacroDef NiceDeclaration |
InvalidNoPositivityCheckPragma Range |

Instances

Pretty DeclarationException # |
Methods pretty :: DeclarationException -> Doc # prettyPrec :: Int -> DeclarationException -> Doc #
Error DeclarationException # |
Methods noMsg :: DeclarationException # strMsg :: String -> DeclarationException #
HasRange DeclarationException # |
Methods getRange :: DeclarationException -> Range #

type Nice = StateT NiceEnv (Either DeclarationException) #

Nicifier monad.

runNice :: Nice a -> Either DeclarationException a #

niceDeclarations :: [Declaration] -> Nice [NiceDeclaration] #

Main.

notSoNiceDeclarations :: NiceDeclaration -> [Declaration] #

(Approximately) convert a `NiceDeclaration` back to a list of `Declaration`s.

niceHasAbstract :: NiceDeclaration -> Maybe IsAbstract #

Has the `NiceDeclaration` a field of type `IsAbstract`?

type Measure = Name #

Termination measure is, for now, a variable name.