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

Safe HaskellNone
LanguageHaskell98

Agda.Syntax.Scope.Base

Contents

Description

This module defines the notion of a scope and operations on scopes.

Synopsis

Scope representation

data Scope

A scope is a named collection of names partitioned into public and private names.

data ScopeInfo

The complete information about the scope at a particular program point includes the scope stack, the local variables, and the context precedence.

type LocalVars = [(Name, Name)]

Local variables.

Name spaces

data NameSpace

A NameSpace contains the mappings from concrete names that the user can write to the abstract fully qualified names that the type checker wants to read.

Constructors

NameSpace 

Fields

nsNames :: NamesInScope

Maps concrete names to a list of abstract names.

nsModules :: ModulesInScope

Maps concrete module names to a list of abstract module names.

type ThingsInScope a = Map Name [a]

data InScopeTag a where

Set of types consisting of exactly AbstractName and AbstractModule.

A GADT just for some dependent-types trickery.

class Eq a => InScope a where

Type class for some dependent-types trickery.

inNameSpace :: forall a. InScope a => NameSpace -> ThingsInScope a

inNameSpace selects either the name map or the module name map from a NameSpace. What is selected is determined by result type (using the dependent-type trickery).

Decorated names

data KindOfName

For the sake of parsing left-hand sides, we distinguish constructor and record field names from defined names.

Constructors

ConName

Constructor name.

FldName

Record field name.

DefName

Ordinary defined name.

PatternSynName

Name of a pattern synonym.

allKindsOfNames :: [KindOfName]

A list containing all name kinds.

data WhyInScope

Where does a name come from?

This information is solely for reporting to the user, see whyInScope.

Constructors

Defined

Defined in this module.

Opened QName WhyInScope

Imported from another module.

Applied QName WhyInScope

Imported by a module application.

data AbstractName

A decoration of QName.

Constructors

AbsName 

Fields

anameName :: QName

The resolved qualified name.

anameKind :: KindOfName

The kind (definition, constructor, record field etc.).

anameLineage :: WhyInScope

Explanation where this name came from.

data AbstractModule

A decoration of abstract syntax module names.

Constructors

AbsModule 

Fields

amodName :: ModuleName

The resolved module name.

amodLineage :: WhyInScope

Explanation where this name came from.

Operations on name and module maps.

Operations on name spaces

emptyNameSpace :: NameSpace

The empty name space.

mapNameSpace :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> NameSpace -> NameSpace

Map functions over the names and modules in a name space.

mapNameSpaceM :: Monad m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> NameSpace -> m NameSpace

Map monadic function over a namespace.

General operations on scopes

emptyScope :: Scope

The empty scope.

emptyScopeInfo :: ScopeInfo

The empty scope info.

mapScope :: (NameSpaceId -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope) -> Scope -> Scope

Map functions over the names and modules in a scope.

mapScope_ :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> Scope -> Scope

Same as mapScope but applies the same function to all name spaces.

mapScopeM :: (Functor m, Monad m) => (NameSpaceId -> NamesInScope -> m NamesInScope) -> (NameSpaceId -> ModulesInScope -> m ModulesInScope) -> Scope -> m Scope

Map monadic functions over the names and modules in a scope.

mapScopeM_ :: (Functor m, Monad m) => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> Scope -> m Scope

Same as mapScopeM but applies the same function to both the public and private name spaces.

zipScope :: (NameSpaceId -> NamesInScope -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope -> ModulesInScope) -> Scope -> Scope -> Scope

Zip together two scopes. The resulting scope has the same name as the first scope.

zipScope_ :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> Scope -> Scope -> Scope

Same as zipScope but applies the same function to both the public and private name spaces.

filterScope :: (Name -> Bool) -> (Name -> Bool) -> Scope -> Scope

Filter a scope keeping only concrete names matching the predicates. The first predicate is applied to the names and the second to the modules.

allNamesInScope :: InScope a => Scope -> ThingsInScope a

Return all names in a scope.

exportedNamesInScope :: InScope a => Scope -> ThingsInScope a

Returns the scope's non-private names.

mergeScope :: Scope -> Scope -> Scope

Merge two scopes. The result has the name of the first scope.

mergeScopes :: [Scope] -> Scope

Merge a non-empty list of scopes. The result has the name of the first scope in the list.

Specific operations on scopes

setScopeAccess :: NameSpaceId -> Scope -> Scope

Move all names in a scope to the given name space (except never move from Imported to Public).

addNamesToScope :: NameSpaceId -> Name -> [AbstractName] -> Scope -> Scope

Add names to a scope.

addNameToScope :: NameSpaceId -> Name -> AbstractName -> Scope -> Scope

Add a name to a scope.

addModuleToScope :: NameSpaceId -> Name -> AbstractModule -> Scope -> Scope

Add a module to a scope.

renameCanonicalNames :: Map QName QName -> Map ModuleName ModuleName -> Scope -> Scope

Rename the abstract names in a scope.

restrictPrivate :: Scope -> Scope

Restrict the private name space of a scope

removeOnlyQualified :: Scope -> Scope

Remove names that can only be used qualified (when opening a scope)

inScopeBecause :: (WhyInScope -> WhyInScope) -> Scope -> Scope

Add an explanation to why things are in scope.

publicModules :: ScopeInfo -> Map ModuleName Scope

Get the public parts of the public modules of a scope

flattenScope :: [[Name]] -> ScopeInfo -> Map QName [AbstractName]

Compute a flattened scope. Only include unqualified names or names qualified by modules in the first argument.

scopeLookup :: InScope a => QName -> ScopeInfo -> [a]

Look up a name in the scope

scopeLookup' :: forall a. InScope a => QName -> ScopeInfo -> [(a, Access)]

Inverse look-up

inverseScopeLookup :: Either ModuleName QName -> ScopeInfo -> Maybe QName

Find the shortest concrete name that maps (uniquely) to a given abstract name.

inverseScopeLookupName :: QName -> ScopeInfo -> Maybe QName

Takes the first component of inverseScopeLookup.

(Debug) printing

blockOfLines :: String -> [String] -> [String]

Add first string only if list is non-empty.

Boring instances