To simplify interaction between scope checking and type checking (in particular when chasing imports), we use the same monad.
ModuleAgda-2.8.0.2Haskell2010
Agda.Syntax.Scope.Monad
The scope monad with operations.
Contents
Synopsis
- type ScopeM
- value printLocals
- value scopeWarning'
- value scopeWarning
- value isDatatypeModule
- value getCurrentModule
- value setCurrentModule
- value withCurrentModule
- value withCurrentModule'
- value getNamedScope
- value getCurrentScope
- value createModule
- value modifyScopes
- value modifyNamedScope
- value setNamedScope
- value modifyNamedScopeM
- value modifyCurrentScope
- value modifyCurrentScopeM
- value modifyCurrentNameSpace
- value setContextPrecedence
- value withContextPrecedence
- value getLocalVars
- value modifyLocalVars
- value setLocalVars
- value withLocalVars
- value outsideLocalVars
- value withCheckNoShadowing
- value checkNoShadowing
- value getVarsToBind
- value addVarToBind
- value bindVarsToBind
- value annotateDecls
- value annotateExpr
- value freshAbstractName
- value freshAbstractName_
- value freshAbstractQName
- value freshAbstractQName'
- value freshConcreteName
- value resolveName
- value resolveName'
- value tryResolveName
- value canHaveSuffixTest
- value resolveModule
- value getConcreteFixity
- value getConcretePolarity
- value computeFixitiesAndPolarities
- value getNotation
- value bindVariable
- value unbindVariable
- value bindName
- value bindName'
- value bindName''
- value rebindName
- value bindModule
- value bindQModule
- value setRecordConstructor
- value getRecordConstructor
- value isRecordConstructor
- value stripNoNames
- type WSM
- data ScopeMemo
- value memoToScopeInfo
- value copyName
- value copyScope
- value checkNoFixityInRenamingModule
- value verifyImportDirective
- value applyImportDirectiveM
- value mapImportDir
- data ImportedNameMap
- value importedNameMapFromList
- value lookupImportedName
- value mapRenaming
- data OpenKind
- value noGeneralizedVarsIfLetOpen
- value openModule_
- value openModule
- PackageAgda-2.8.0.2
- Exports76
- LanguageHaskell2010
- LicenceMIT
- SourceMonad.hs
The scope checking monad
General operations
Create a new module with an empty scope.
If the module is not new (e.g. duplicate import),
don't erase its contents.
(Just if it is a datatype or record module.)
Apply a function to the scope map.
Apply a function to the given scope.
Apply a monadic function to the top scope.
Apply a function to the current scope.
Apply a function to the public or private name space.
Run a computation without changing the local variables.
Run a computation outside some number of local variables and add them back afterwards. This lets you bind variables in the middle of the context and is used when binding generalizable variables (#3735).
Check that the newly added variable have unique names.
After collecting some variable names in the scopeVarsToBind, bind them all simultaneously.
Names
Create a fresh abstract name from a concrete name.
This function is used when we translate a concrete name in a binder. The Range of the concrete name is saved as the nameBindingSite of the abstract name.
freshAbstractName_ = freshAbstractName noFixity'Create a fresh abstract qualified name.
Create a concrete name that is not yet in scope.
| NOTE: See chooseName in Agda.Syntax.Translation.AbstractToConcrete for similar logic.
| NOTE: See withName in Agda.Syntax.Translation.ReflectedToAbstract for similar logic.
Resolving names
Look up the abstract name referred to by a given concrete name.
Look up the abstract name corresponding to a concrete name of a certain kind and/or from a given set of names. Sometimes we know already that we are dealing with a constructor or pattern synonym (e.g. when we have parsed a pattern). Then, we can ignore conflicting definitions of that name of a different kind. (See issue 822.)
tryResolveName :: (ReadTCState m, HasBuiltins m, MonadError NameResolutionError m)=> KindsOfNamesRestrict search to these kinds of names.
-> Maybe (Set1 Name)Unless Nothing, restrict search to match any of these names.
-> QNameName to be resolved
-> m ResolvedNameIf illegally ambiguous, throw error with the ambiguous name.
Test if a given abstract name can appear with a suffix. Currently only true for the names of builtin sorts.
Look up a module in the scope.
Get the fixity of a not yet bound name.
Get the polarities of a not yet bound name.
Collect the fixity/syntax declarations and polarity pragmas from the list of declarations and store them in the scope.
getNotation :: QName-> Set1 NameThe name must correspond to one of the names in this set.
-> ScopeM NewNotation
Get the notation of a name. The name is assumed to be in scope.
Binding names
bindVariable :: BindingSourceλ,Π,let, ...?-> NameConcrete name.
-> NameAbstract name.
-> ScopeM ()
Bind a variable.
Temporarily unbind a variable. Used for non-recursive lets.
Bind a defined name. Must not shadow anything.
Bind a name. Returns the TypeError if exists, but does not throw it.
Rebind a name. Use with care! Ulf, 2014-06-29: Currently used to rebind the name defined by an unquoteDecl, which is a QuotableName in the body, but a DefinedName later on.
Bind a module name.
Bind a qualified module name. Adds it to the imports field of the scope.
Operations to do with record constructor names
Record (ha) that a given record has the specified constructor name.
Is this the qualified name which refers to the constructor of an
anonymous record (like Foo.constructor)?
If so, return the part of the name referring to the record (Foo).
Module manipulation operations
Clear the scope of any no names.
Constructors
ScopeMemomemoNames :: Ren QNamememoModules :: Map ModuleName (ModuleName, Bool)Bool: did we copy recursively? We need to track this because we don't copy recursively when creating new modules for reexported functions (issue1985), but we might need to copy recursively later.
Mark a name as being a copy in the TC state.
Create a new scope with the given name from an old scope. Renames public names in the old scope to match the new name and returns the renamings.
Import directives
Warn about useless fixity declarations in renaming directives.
Monadic for the sake of error reporting.
Check that an import directive doesn't contain repeated names.
applyImportDirectiveM :: QNameName of the scope, only for error reporting.
-> ImportDirectiveDescription of how scope is to be modified.
-> ScopeInput scope.
-> ScopeM (ImportDirective, Scope)Scope-checked description, output scope.
Apply an import directive and check that all the names mentioned actually exist.
Monadic for the sake of error reporting.
mapImportDir :: (Ord n1, Ord m1)=> [ImportedName' (n1, n2) (m1, m2)]Translation of imported names.
-> [ImportedName' (n1, n2) (m1, m2)]Translation of names defined by this import.
-> ImportDirective' n1 m1-> ImportDirective' n2 m2
Translation of ImportDirective.
A finite map for ImportedNames.
Constructors
ImportedNameMapinameMap :: Map n1 n2imoduleMap :: Map m1 m2
Create a ImportedNameMap.
Apply a ImportedNameMap.
mapRenaming :: (Ord n1, Ord m1)=> ImportedNameMap n1 n2 m1 m2Translation of renFrom names and module names.
-> ImportedNameMap n1 n2 m1 m2Translation of
rentonames and module names.-> Renaming' n1 m1Renaming before translation (1).
-> Renaming' n2 m2Renaming after translation (2).
Translation of Renaming.
Opening a module
Open a module.
Open a module, possibly given an already resolved module name.