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

Safe Haskell | None
Language | Haskell2010

Agda.Syntax.Scope.Monad

Contents

- The scope checking monad
- Errors
- General operations
- Names
- Resolving names
- Binding names
- Module manipulation operations
- Orphan instances

Description

The scope monad with operations.

Synopsis

- type ScopeM = TCM
- isDatatypeModule :: ModuleName -> ScopeM (Maybe DataOrRecord)
- printLocals :: Int -> String -> ScopeM ()
- getCurrentModule :: ScopeM ModuleName
- setCurrentModule :: ModuleName -> ScopeM ()
- withCurrentModule :: ModuleName -> ScopeM a -> ScopeM a
- withCurrentModule' :: (MonadTrans t, Monad (t ScopeM)) => ModuleName -> t ScopeM a -> t ScopeM a
- getNamedScope :: ModuleName -> ScopeM Scope
- getCurrentScope :: ScopeM Scope
- createModule :: Maybe DataOrRecord -> ModuleName -> ScopeM ()
- modifyScopes :: (Map ModuleName Scope -> Map ModuleName Scope) -> ScopeM ()
- modifyNamedScope :: ModuleName -> (Scope -> Scope) -> ScopeM ()
- setNamedScope :: ModuleName -> Scope -> ScopeM ()
- modifyNamedScopeM :: ModuleName -> (Scope -> ScopeM (a, Scope)) -> ScopeM a
- modifyCurrentScope :: (Scope -> Scope) -> ScopeM ()
- modifyCurrentScopeM :: (Scope -> ScopeM (a, Scope)) -> ScopeM a
- modifyCurrentNameSpace :: NameSpaceId -> (NameSpace -> NameSpace) -> ScopeM ()
- pushContextPrecedence :: Precedence -> ScopeM PrecedenceStack
- setContextPrecedence :: PrecedenceStack -> ScopeM ()
- withContextPrecedence :: Precedence -> ScopeM a -> ScopeM a
- getLocalVars :: ScopeM LocalVars
- modifyLocalVars :: (LocalVars -> LocalVars) -> ScopeM ()
- setLocalVars :: LocalVars -> ScopeM ()
- withLocalVars :: ScopeM a -> ScopeM a
- getVarsToBind :: ScopeM LocalVars
- addVarToBind :: Name -> LocalVar -> ScopeM ()
- bindVarsToBind :: ScopeM ()
- freshAbstractName :: Fixity' -> Name -> ScopeM Name
- freshAbstractName_ :: Name -> ScopeM Name
- freshAbstractQName :: Fixity' -> Name -> ScopeM QName
- freshAbstractQName' :: Name -> ScopeM QName
- resolveName :: QName -> ScopeM ResolvedName
- resolveName' :: [KindOfName] -> Maybe (Set Name) -> QName -> ScopeM ResolvedName
- resolveModule :: QName -> ScopeM AbstractModule
- getConcreteFixity :: Name -> ScopeM Fixity'
- getConcretePolarity :: Name -> ScopeM (Maybe [Occurrence])
- computeFixitiesAndPolarities :: DoWarn -> [Declaration] -> ScopeM a -> ScopeM a
- getNotation :: QName -> Set Name -> ScopeM NewNotation
- bindVariable :: Binder -> Name -> Name -> ScopeM ()
- unbindVariable :: Name -> ScopeM a -> ScopeM a
- bindName :: Access -> KindOfName -> Name -> QName -> ScopeM ()
- bindName' :: Access -> KindOfName -> NameMetadata -> Name -> QName -> ScopeM ()
- rebindName :: Access -> KindOfName -> Name -> QName -> ScopeM ()
- bindModule :: Access -> Name -> ModuleName -> ScopeM ()
- bindQModule :: Access -> QName -> ModuleName -> ScopeM ()
- stripNoNames :: ScopeM ()
- type WSM = StateT ScopeMemo ScopeM
- data ScopeMemo = ScopeMemo {
  - memoNames :: Ren QName
  - memoModules :: [(ModuleName, (ModuleName, Bool))]
  }
- memoToScopeInfo :: ScopeMemo -> ScopeCopyInfo
- copyScope :: QName -> ModuleName -> Scope -> ScopeM (Scope, ScopeCopyInfo)
- applyImportDirectiveM :: QName -> ImportDirective -> Scope -> ScopeM (ImportDirective, Scope)
- lookupImportedName :: (Eq a, Eq b) => ImportedName' a b -> [ImportedName' (a, c) (b, d)] -> ImportedName' c d
- mapImportDir :: (Eq n1, Eq m1) => [ImportedName' (n1, n2) (m1, m2)] -> [ImportedName' (n1, n2) (m1, m2)] -> ImportDirective' n1 m1 -> ImportDirective' n2 m2
- mapUsing :: (Eq n1, Eq m1) => [ImportedName' (n1, n2) (m1, m2)] -> Using' n1 m1 -> Using' n2 m2
- mapRenaming :: (Eq n1, Eq m1) => [ImportedName' (n1, n2) (m1, m2)] -> [ImportedName' (n1, n2) (m1, m2)] -> Renaming' n1 m1 -> Renaming' n2 m2
- data OpenKind
  - = LetOpenModule
  - | TopOpenModule
- noGeneralizedVarsIfLetOpen :: OpenKind -> Scope -> Scope
- openModule_ :: OpenKind -> QName -> ImportDirective -> ScopeM ImportDirective

# The scope checking monad

type ScopeM = TCM Source #

To simplify interaction between scope checking and type checking (in particular when chasing imports), we use the same monad.

# Errors

isDatatypeModule :: ModuleName -> ScopeM (Maybe DataOrRecord) Source #

printLocals :: Int -> String -> ScopeM () Source #

# General operations

getCurrentModule :: ScopeM ModuleName Source #

setCurrentModule :: ModuleName -> ScopeM () Source #

withCurrentModule :: ModuleName -> ScopeM a -> ScopeM a Source #

withCurrentModule' :: (MonadTrans t, Monad (t ScopeM)) => ModuleName -> t ScopeM a -> t ScopeM a Source #

getNamedScope :: ModuleName -> ScopeM Scope Source #

getCurrentScope :: ScopeM Scope Source #

createModule :: Maybe DataOrRecord -> ModuleName -> ScopeM () Source #

Create a new module with an empty scope. (`Just` if it is a datatype or record module.)

modifyScopes :: (Map ModuleName Scope -> Map ModuleName Scope) -> ScopeM () Source #

Apply a function to the scope map.

modifyNamedScope :: ModuleName -> (Scope -> Scope) -> ScopeM () Source #

Apply a function to the given scope.

setNamedScope :: ModuleName -> Scope -> ScopeM () Source #

modifyNamedScopeM :: ModuleName -> (Scope -> ScopeM (a, Scope)) -> ScopeM a Source #

Apply a monadic function to the top scope.

modifyCurrentScope :: (Scope -> Scope) -> ScopeM () Source #

Apply a function to the current scope.

modifyCurrentScopeM :: (Scope -> ScopeM (a, Scope)) -> ScopeM a Source #

modifyCurrentNameSpace :: NameSpaceId -> (NameSpace -> NameSpace) -> ScopeM () Source #

Apply a function to the public or private name space.

pushContextPrecedence :: Precedence -> ScopeM PrecedenceStack Source #

setContextPrecedence :: PrecedenceStack -> ScopeM () Source #

withContextPrecedence :: Precedence -> ScopeM a -> ScopeM a Source #

getLocalVars :: ScopeM LocalVars Source #

modifyLocalVars :: (LocalVars -> LocalVars) -> ScopeM () Source #

setLocalVars :: LocalVars -> ScopeM () Source #

withLocalVars :: ScopeM a -> ScopeM a Source #

Run a computation without changing the local variables.

getVarsToBind :: ScopeM LocalVars Source #

addVarToBind :: Name -> LocalVar -> ScopeM () Source #

bindVarsToBind :: ScopeM () Source #

After collecting some variable names in the scopeVarsToBind, bind them all simultaneously.

# Names

freshAbstractName :: Fixity' -> Name -> ScopeM Name Source #

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_ :: Name -> ScopeM Name Source #

    freshAbstractName_ = freshAbstractName noFixity'

freshAbstractQName :: Fixity' -> Name -> ScopeM QName Source #

Create a fresh abstract qualified name.

freshAbstractQName' :: Name -> ScopeM QName Source #

# Resolving names

resolveName :: QName -> ScopeM ResolvedName Source #

Look up the abstract name referred to by a given concrete name.

resolveName' :: [KindOfName] -> Maybe (Set Name) -> QName -> ScopeM ResolvedName Source #

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.)

resolveModule :: QName -> ScopeM AbstractModule Source #

Look up a module in the scope.

getConcreteFixity :: Name -> ScopeM Fixity' Source #

Get the fixity of a not yet bound name.

getConcretePolarity :: Name -> ScopeM (Maybe [Occurrence]) Source #

Get the polarities of a not yet bound name.

computeFixitiesAndPolarities :: DoWarn -> [Declaration] -> ScopeM a -> ScopeM a Source #

Collect the fixity/syntax declarations and polarity pragmas from the list of declarations and store them in the scope.

getNotation Source #

Arguments

:: QName |
-> Set Name | The 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 Source #

Arguments

:: Binder | `λ`, `Π`, `let`, ...?
-> Name | Concrete name.
-> Name | Abstract name.
-> ScopeM () |

Bind a variable.

unbindVariable :: Name -> ScopeM a -> ScopeM a Source #

Temporarily unbind a variable. Used for non-recursive lets.

bindName :: Access -> KindOfName -> Name -> QName -> ScopeM () Source #

Bind a defined name. Must not shadow anything.

bindName' :: Access -> KindOfName -> NameMetadata -> Name -> QName -> ScopeM () Source #

rebindName :: Access -> KindOfName -> Name -> QName -> ScopeM () Source #

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.

bindModule :: Access -> Name -> ModuleName -> ScopeM () Source #

Bind a module name.

bindQModule :: Access -> QName -> ModuleName -> ScopeM () Source #

Bind a qualified module name. Adds it to the imports field of the scope.

# Module manipulation operations

stripNoNames :: ScopeM () Source #

Clear the scope of any no names.

type WSM = StateT ScopeMemo ScopeM Source #

data ScopeMemo Source #

Constructors

ScopeMemo |

Fields

- memoNames :: Ren QName
- memoModules :: [(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.

memoToScopeInfo :: ScopeMemo -> ScopeCopyInfo Source #

copyScope :: QName -> ModuleName -> Scope -> ScopeM (Scope, ScopeCopyInfo) Source #

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.

applyImportDirectiveM :: QName -> ImportDirective -> Scope -> ScopeM (ImportDirective, Scope) Source #

Apply an import directive and check that all the names mentioned actually exist.

lookupImportedName :: (Eq a, Eq b) => ImportedName' a b -> [ImportedName' (a, c) (b, d)] -> ImportedName' c d Source #

A finite map for `ImportedName`s.

mapImportDir Source #

Arguments

:: (Eq n1, Eq 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`.

mapUsing Source #

Arguments

:: (Eq n1, Eq m1) |
=> [ImportedName' (n1, n2) (m1, m2)] | Translation of names in `using` or `hiding` list.
-> Using' n1 m1 |
-> Using' n2 m2 |

Translation of `Using or Hiding`.

mapRenaming Source #

Arguments

:: (Eq n1, Eq m1) |
=> [ImportedName' (n1, n2) (m1, m2)] | Translation of `renFrom` names and module names.
-> [ImportedName' (n1, n2) (m1, m2)] | Translation of `rento` names and module names.
-> Renaming' n1 m1 | Renaming before translation (1).
-> Renaming' n2 m2 | Renaming after translation (2).

Translation of `Renaming`.

data OpenKind Source #

Constructors

LetOpenModule |
TopOpenModule |

noGeneralizedVarsIfLetOpen :: OpenKind -> Scope -> Scope Source #

openModule_ :: OpenKind -> QName -> ImportDirective -> ScopeM ImportDirective Source #

Open a module.

# Orphan instances

MonadFixityError ScopeM Source # |

Instance details

Methods

throwMultipleFixityDecls :: [(Name, [Fixity'])] -> ScopeM a Source #

throwMultiplePolarityPragmas :: [Name] -> ScopeM a Source #

warnUnknownNamesInFixityDecl :: [Name] -> ScopeM () Source #

warnUnknownNamesInPolarityPragmas :: [Name] -> ScopeM () Source #

warnUnknownFixityInMixfixDecl :: [Name] -> ScopeM () Source #

warnPolarityPragmasButNotPostulates :: [Name] -> ScopeM () Source #