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

Safe Haskell | None
Language | Haskell2010

Agda.Syntax.Scope.Base

Contents

- Scope representation
- Name spaces
- Decorated names
- Operations on name and module maps.
- Operations on name spaces
- General operations on scopes
- Specific operations on scopes
- Inverse look-up
- (Debug) printing
- Boring instances

Description

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

Synopsis

- data Scope = Scope {
  - scopeName :: ModuleName
  - scopeParents :: [ModuleName]
  - scopeNameSpaces :: ScopeNameSpaces
  - scopeImports :: Map QName ModuleName
  - scopeDatatypeModule :: Bool
  }
- data NameSpaceId
  - = PrivateNS
  - | PublicNS
  - | ImportedNS
  - | OnlyQualifiedNS
- type ScopeNameSpaces = [(NameSpaceId, NameSpace)]
- localNameSpace :: Access -> NameSpaceId
- nameSpaceAccess :: NameSpaceId -> Access
- scopeNameSpace :: NameSpaceId -> Scope -> NameSpace
- updateScopeNameSpaces :: (ScopeNameSpaces -> ScopeNameSpaces) -> Scope -> Scope
- updateScopeNameSpacesM :: Functor m => (ScopeNameSpaces -> m ScopeNameSpaces) -> Scope -> m Scope
- data ScopeInfo = ScopeInfo {
  - scopeCurrent :: ModuleName
  - scopeModules :: Map ModuleName Scope
  - scopeLocals :: LocalVars
  - scopePrecedence :: Precedence
  - scopeInverseName :: Map QName [QName]
  - scopeInverseModule :: Map ModuleName [QName]
  - scopeInScope :: InScopeSet
  }
- type LocalVars = AssocList Name LocalVar
- data LocalVar
  - = LocalVar {
    - localVar :: Name
    }
  - | ShadowedVar {
    - localVar :: Name
    - localShadowedBy :: [AbstractName]
    }
- shadowLocal :: [AbstractName] -> LocalVar -> LocalVar
- notShadowedLocal :: LocalVar -> Maybe Name
- notShadowedLocals :: LocalVars -> AssocList Name Name
- updateScopeLocals :: (LocalVars -> LocalVars) -> ScopeInfo -> ScopeInfo
- setScopeLocals :: LocalVars -> ScopeInfo -> ScopeInfo
- mapScopeInfo :: (Scope -> Scope) -> ScopeInfo -> ScopeInfo
- data NameSpace = NameSpace {
  - nsNames :: NamesInScope
  - nsModules :: ModulesInScope
  - nsInScope :: InScopeSet
  }
- type ThingsInScope a = Map Name [a]
- type NamesInScope = ThingsInScope AbstractName
- type ModulesInScope = ThingsInScope AbstractModule
- type InScopeSet = Set QName
- data InScopeTag a where
  - NameTag :: InScopeTag AbstractName
  - ModuleTag :: InScopeTag AbstractModule
- class Eq a => InScope a where
- inNameSpace :: forall a. InScope a => NameSpace -> ThingsInScope a
- data KindOfName
  - = ConName
  - | FldName
  - | DefName
  - | PatternSynName
  - | MacroName
  - | QuotableName
- allKindsOfNames :: [KindOfName]
- data WhyInScope
  - = Defined
  - | Opened QName WhyInScope
  - | Applied QName WhyInScope
- data AbstractName = AbsName {
  - anameName :: QName
  - anameKind :: KindOfName
  - anameLineage :: WhyInScope
  }
- data AbstractModule = AbsModule {
  - amodName :: ModuleName
  - amodLineage :: WhyInScope
  }
- lensAnameName :: Functor m => (QName -> m QName) -> AbstractName -> m AbstractName
- lensAmodName :: Functor m => (ModuleName -> m ModuleName) -> AbstractModule -> m AbstractModule
- mergeNames :: Eq a => ThingsInScope a -> ThingsInScope a -> ThingsInScope a
- emptyNameSpace :: NameSpace
- mapNameSpace :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> NameSpace -> NameSpace
- zipNameSpace :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet -> InScopeSet) -> NameSpace -> NameSpace -> NameSpace
- mapNameSpaceM :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> NameSpace -> m NameSpace
- emptyScope :: Scope
- emptyScopeInfo :: ScopeInfo
- mapScope :: (NameSpaceId -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope) -> (NameSpaceId -> InScopeSet -> InScopeSet) -> Scope -> Scope
- mapScope_ :: (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> Scope -> Scope
- mapScope' :: NameSpaceId -> (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> Scope -> Scope
- mapScopeM :: Applicative m => (NameSpaceId -> NamesInScope -> m NamesInScope) -> (NameSpaceId -> ModulesInScope -> m ModulesInScope) -> (NameSpaceId -> InScopeSet -> m InScopeSet) -> Scope -> m Scope
- mapScopeM_ :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> Scope -> m Scope
- zipScope :: (NameSpaceId -> NamesInScope -> NamesInScope -> NamesInScope) -> (NameSpaceId -> ModulesInScope -> ModulesInScope -> ModulesInScope) -> (NameSpaceId -> InScopeSet -> InScopeSet -> InScopeSet) -> Scope -> Scope -> Scope
- zipScope_ :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet -> InScopeSet) -> Scope -> Scope -> Scope
- recomputeInScopeSets :: Scope -> Scope
- filterScope :: (Name -> Bool) -> (Name -> Bool) -> Scope -> Scope
- allNamesInScope :: InScope a => Scope -> ThingsInScope a
- allNamesInScope' :: InScope a => Scope -> ThingsInScope (a, Access)
- exportedNamesInScope :: InScope a => Scope -> ThingsInScope a
- namesInScope :: InScope a => [NameSpaceId] -> Scope -> ThingsInScope a
- allThingsInScope :: Scope -> NameSpace
- thingsInScope :: [NameSpaceId] -> Scope -> NameSpace
- mergeScope :: Scope -> Scope -> Scope
- mergeScopes :: [Scope] -> Scope
- setScopeAccess :: NameSpaceId -> Scope -> Scope
- setNameSpace :: NameSpaceId -> NameSpace -> Scope -> Scope
- modifyNameSpace :: NameSpaceId -> (NameSpace -> NameSpace) -> Scope -> Scope
- addNamesToScope :: NameSpaceId -> Name -> [AbstractName] -> Scope -> Scope
- addNameToScope :: NameSpaceId -> Name -> AbstractName -> Scope -> Scope
- removeNameFromScope :: NameSpaceId -> Name -> Scope -> Scope
- addModuleToScope :: NameSpaceId -> Name -> AbstractModule -> Scope -> Scope
- type UsingOrHiding = Either Using [ImportedName]
- usingOrHiding :: ImportDirective -> UsingOrHiding
- applyImportDirective :: ImportDirective -> Scope -> Scope
- renameCanonicalNames :: Map QName QName -> Map ModuleName ModuleName -> Scope -> Scope
- restrictPrivate :: Scope -> Scope
- restrictLocalPrivate :: ModuleName -> Scope -> Scope
- removeOnlyQualified :: Scope -> Scope
- inScopeBecause :: (WhyInScope -> WhyInScope) -> Scope -> Scope
- publicModules :: ScopeInfo -> Map ModuleName Scope
- publicNames :: ScopeInfo -> Set AbstractName
- everythingInScope :: ScopeInfo -> NameSpace
- flattenScope :: [[Name]] -> ScopeInfo -> Map QName [AbstractName]
- concreteNamesInScope :: ScopeInfo -> Set QName
- scopeLookup :: InScope a => QName -> ScopeInfo -> [a]
- scopeLookup' :: forall a. InScope a => QName -> ScopeInfo -> [(a, Access)]
- data AllowAmbiguousNames
  - = AmbiguousAnything
  - | AmbiguousConProjs
  - | AmbiguousNothing
- isNameInScope :: QName -> ScopeInfo -> Bool
- inverseScopeLookup :: Either ModuleName QName -> ScopeInfo -> [QName]
- inverseScopeLookup' :: AllowAmbiguousNames -> Either ModuleName QName -> ScopeInfo -> [QName]
- recomputeInverseScopeMaps :: ScopeInfo -> ScopeInfo
- inverseScopeLookupName :: QName -> ScopeInfo -> [QName]
- inverseScopeLookupName' :: AllowAmbiguousNames -> QName -> ScopeInfo -> [QName]
- inverseScopeLookupModule :: ModuleName -> ScopeInfo -> [QName]
- blockOfLines :: String -> [String] -> [String]

# Scope representation

data Scope #

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

Constructors

Scope |
Fields scopeName :: ModuleName scopeParents :: [ModuleName] scopeNameSpaces :: ScopeNameSpaces scopeImports :: Map QName ModuleName scopeDatatypeModule :: Bool

Instances

Eq Scope # |
Methods (==) :: Scope -> Scope -> Bool # (/=) :: Scope -> Scope -> Bool #
Show Scope # |
Methods showsPrec :: Int -> Scope -> ShowS # show :: Scope -> String # showList :: [Scope] -> ShowS #
InstantiateFull Scope # |
Methods instantiateFull' :: Scope -> ReduceM Scope #

data NameSpaceId #

See `Access`.

Constructors

PrivateNS | Things not exported by this module.
PublicNS | Things defined and exported by this module.
ImportedNS | Things from open public, exported by this module.
OnlyQualifiedNS | Visible (as qualified) from outside, but not exported when opening the module. Used for qualified constructors.

Instances

Bounded NameSpaceId # |
Methods minBound :: NameSpaceId # maxBound :: NameSpaceId #
Enum NameSpaceId # |
Methods succ :: NameSpaceId -> NameSpaceId # pred :: NameSpaceId -> NameSpaceId # toEnum :: Int -> NameSpaceId # fromEnum :: NameSpaceId -> Int # enumFrom :: NameSpaceId -> [NameSpaceId] # enumFromThen :: NameSpaceId -> NameSpaceId -> [NameSpaceId] # enumFromTo :: NameSpaceId -> NameSpaceId -> [NameSpaceId] # enumFromThenTo :: NameSpaceId -> NameSpaceId -> NameSpaceId -> [NameSpaceId] #
Eq NameSpaceId # |
Methods (==) :: NameSpaceId -> NameSpaceId -> Bool # (/=) :: NameSpaceId -> NameSpaceId -> Bool #
Show NameSpaceId # |
Methods showsPrec :: Int -> NameSpaceId -> ShowS # show :: NameSpaceId -> String # showList :: [NameSpaceId] -> ShowS #

type ScopeNameSpaces = [(NameSpaceId, NameSpace)] #

localNameSpace :: Access -> NameSpaceId #

nameSpaceAccess :: NameSpaceId -> Access #

scopeNameSpace :: NameSpaceId -> Scope -> NameSpace #

Get a `NameSpace` from `Scope`.

updateScopeNameSpaces :: (ScopeNameSpaces -> ScopeNameSpaces) -> Scope -> Scope #

A lens for `scopeNameSpaces`

updateScopeNameSpacesM :: Functor m => (ScopeNameSpaces -> m ScopeNameSpaces) -> Scope -> m Scope #

``Monadic'` lens (Functor sufficient).

data ScopeInfo #

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

Constructors

ScopeInfo |
Fields scopeCurrent :: ModuleName scopeModules :: Map ModuleName Scope scopeLocals :: LocalVars scopePrecedence :: Precedence scopeInverseName :: Map QName [QName] scopeInverseModule :: Map ModuleName [QName] scopeInScope :: InScopeSet

Instances

Eq ScopeInfo # |
Methods (==) :: ScopeInfo -> ScopeInfo -> Bool # (/=) :: ScopeInfo -> ScopeInfo -> Bool #
Show ScopeInfo # |
Methods showsPrec :: Int -> ScopeInfo -> ShowS # show :: ScopeInfo -> String # showList :: [ScopeInfo] -> ShowS #
KillRange ScopeInfo # |
Methods killRange :: KillRangeT ScopeInfo #

type LocalVars = AssocList Name LocalVar #

Local variables.

data LocalVar #

A local variable can be shadowed by an import. In case of reference to a shadowed variable, we want to report a scope error.

Constructors

LocalVar | Unique ID of local variable.
Fields localVar :: Name
ShadowedVar | This local variable is shadowed by one or more imports. (List not empty).
Fields localVar :: Name localShadowedBy :: [AbstractName]

Instances

Eq LocalVar # |
Methods (==) :: LocalVar -> LocalVar -> Bool # (/=) :: LocalVar -> LocalVar -> Bool #
Ord LocalVar # |
Methods compare :: LocalVar -> LocalVar -> Ordering # (<) :: LocalVar -> LocalVar -> Bool # (<=) :: LocalVar -> LocalVar -> Bool # (>) :: LocalVar -> LocalVar -> Bool # (>=) :: LocalVar -> LocalVar -> Bool # max :: LocalVar -> LocalVar -> LocalVar # min :: LocalVar -> LocalVar -> LocalVar #
Show LocalVar # | We show shadowed variables as prefixed by a ".", as not in scope.
Methods showsPrec :: Int -> LocalVar -> ShowS # show :: LocalVar -> String # showList :: [LocalVar] -> ShowS #

shadowLocal :: [AbstractName] -> LocalVar -> LocalVar #

Shadow a local name by a non-empty list of imports.

notShadowedLocal :: LocalVar -> Maybe Name #

Project name of unshadowed local variable.

notShadowedLocals :: LocalVars -> AssocList Name Name #

Get all locals that are not shadowed by imports.

updateScopeLocals :: (LocalVars -> LocalVars) -> ScopeInfo -> ScopeInfo #

Lens for `scopeLocals`.

setScopeLocals :: LocalVars -> ScopeInfo -> ScopeInfo #

mapScopeInfo :: (Scope -> Scope) -> ScopeInfo -> ScopeInfo #

# 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. nsInScope :: InScopeSet

Instances

Eq NameSpace # |
Methods (==) :: NameSpace -> NameSpace -> Bool # (/=) :: NameSpace -> NameSpace -> Bool #
Show NameSpace # |
Methods showsPrec :: Int -> NameSpace -> ShowS # show :: NameSpace -> String # showList :: [NameSpace] -> ShowS #

type ThingsInScope a = Map Name [a] #

type NamesInScope = ThingsInScope AbstractName #

type ModulesInScope = ThingsInScope AbstractModule #

type InScopeSet = Set QName #

data InScopeTag a where #

Set of types consisting of exactly `AbstractName` and `AbstractModule`.

A GADT just for some dependent-types trickery.

Constructors

NameTag :: InScopeTag AbstractName |
ModuleTag :: InScopeTag AbstractModule |

class Eq a => InScope a where #

Type class for some dependent-types trickery.

Minimal complete definition

inScopeTag

Methods

inScopeTag :: InScopeTag a #

Instances

InScope AbstractModule # |
Methods inScopeTag :: InScopeTag AbstractModule #
InScope AbstractName # |
Methods inScopeTag :: InScopeTag AbstractName #

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.
MacroName | Name of a macro
QuotableName | A name that can only be quoted.

Instances

Bounded KindOfName # |
Methods minBound :: KindOfName # maxBound :: KindOfName #
Enum KindOfName # |
Methods succ :: KindOfName -> KindOfName # pred :: KindOfName -> KindOfName # toEnum :: Int -> KindOfName # fromEnum :: KindOfName -> Int # enumFrom :: KindOfName -> [KindOfName] # enumFromThen :: KindOfName -> KindOfName -> [KindOfName] # enumFromTo :: KindOfName -> KindOfName -> [KindOfName] # enumFromThenTo :: KindOfName -> KindOfName -> KindOfName -> [KindOfName] #
Eq KindOfName # |
Methods (==) :: KindOfName -> KindOfName -> Bool # (/=) :: KindOfName -> KindOfName -> Bool #
Show KindOfName # |
Methods showsPrec :: Int -> KindOfName -> ShowS # show :: KindOfName -> String # showList :: [KindOfName] -> ShowS #

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.

Instances

Eq AbstractName # |
Methods (==) :: AbstractName -> AbstractName -> Bool # (/=) :: AbstractName -> AbstractName -> Bool #
Ord AbstractName # |
Methods compare :: AbstractName -> AbstractName -> Ordering # (<) :: AbstractName -> AbstractName -> Bool # (<=) :: AbstractName -> AbstractName -> Bool # (>) :: AbstractName -> AbstractName -> Bool # (>=) :: AbstractName -> AbstractName -> Bool # max :: AbstractName -> AbstractName -> AbstractName # min :: AbstractName -> AbstractName -> AbstractName #
Show AbstractName # |
Methods showsPrec :: Int -> AbstractName -> ShowS # show :: AbstractName -> String # showList :: [AbstractName] -> ShowS #
SetRange AbstractName # |
Methods setRange :: Range -> AbstractName -> AbstractName #
HasRange AbstractName # |
Methods getRange :: AbstractName -> Range #
InScope AbstractName # |
Methods inScopeTag :: InScopeTag AbstractName #

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.

Instances

Eq AbstractModule # |
Methods (==) :: AbstractModule -> AbstractModule -> Bool # (/=) :: AbstractModule -> AbstractModule -> Bool #
Ord AbstractModule # |
Methods compare :: AbstractModule -> AbstractModule -> Ordering # (<) :: AbstractModule -> AbstractModule -> Bool # (<=) :: AbstractModule -> AbstractModule -> Bool # (>) :: AbstractModule -> AbstractModule -> Bool # (>=) :: AbstractModule -> AbstractModule -> Bool # max :: AbstractModule -> AbstractModule -> AbstractModule # min :: AbstractModule -> AbstractModule -> AbstractModule #
Show AbstractModule # |
Methods showsPrec :: Int -> AbstractModule -> ShowS # show :: AbstractModule -> String # showList :: [AbstractModule] -> ShowS #
InScope AbstractModule # |
Methods inScopeTag :: InScopeTag AbstractModule #

lensAnameName :: Functor m => (QName -> m QName) -> AbstractName -> m AbstractName #

Van Laarhoven lens on `anameName`.

lensAmodName :: Functor m => (ModuleName -> m ModuleName) -> AbstractModule -> m AbstractModule #

Van Laarhoven lens on `amodName`.

# Operations on name and module maps.

mergeNames :: Eq a => ThingsInScope a -> ThingsInScope a -> ThingsInScope a #

# Operations on name spaces

emptyNameSpace :: NameSpace #

The empty name space.

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

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

zipNameSpace :: (NamesInScope -> NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet -> InScopeSet) -> NameSpace -> NameSpace -> NameSpace #

Zip together two name spaces.

mapNameSpaceM :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> 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) -> (NameSpaceId -> InScopeSet -> InScopeSet) -> Scope -> Scope #

Map functions over the names and modules in a scope.

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

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

mapScope' :: NameSpaceId -> (NamesInScope -> NamesInScope) -> (ModulesInScope -> ModulesInScope) -> (InScopeSet -> InScopeSet) -> Scope -> Scope #

Same as `mapScope` but applies the function only on the given name space.

mapScopeM :: Applicative m => (NameSpaceId -> NamesInScope -> m NamesInScope) -> (NameSpaceId -> ModulesInScope -> m ModulesInScope) -> (NameSpaceId -> InScopeSet -> m InScopeSet) -> Scope -> m Scope #

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

mapScopeM_ :: Applicative m => (NamesInScope -> m NamesInScope) -> (ModulesInScope -> m ModulesInScope) -> (InScopeSet -> m InScopeSet) -> 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) -> (NameSpaceId -> InScopeSet -> InScopeSet -> InScopeSet) -> 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) -> (InScopeSet -> InScopeSet -> InScopeSet) -> Scope -> Scope -> Scope #

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

recomputeInScopeSets :: Scope -> Scope #

Recompute the inScope sets of a scope.

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.

allNamesInScope' :: InScope a => Scope -> ThingsInScope (a, Access) #

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

Returns the scope's non-private names.

namesInScope :: InScope a => [NameSpaceId] -> Scope -> ThingsInScope a #

allThingsInScope :: Scope -> NameSpace #

thingsInScope :: [NameSpaceId] -> Scope -> NameSpace #

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

setNameSpace :: NameSpaceId -> NameSpace -> Scope -> Scope #

Update a particular name space.

modifyNameSpace :: NameSpaceId -> (NameSpace -> NameSpace) -> Scope -> Scope #

Modify a particular name space.

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

Add names to a scope.

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

Add a name to a scope.

removeNameFromScope :: NameSpaceId -> Name -> Scope -> Scope #

Remove a name from a scope. Caution: does not update the nsInScope set. This is only used by rebindName and in that case we add the name right back (but with a different kind).

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

Add a module to a scope.

type UsingOrHiding = Either Using [ImportedName] #

usingOrHiding :: ImportDirective -> UsingOrHiding #

applyImportDirective :: ImportDirective -> Scope -> Scope #

Apply an `ImportDirective` to a scope.

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

Rename the abstract names in a scope.

restrictPrivate :: Scope -> Scope #

Remove private name space of a scope.

Should be a right identity for `exportedNamesInScope`. `exportedNamesInScope . restrictPrivate == exportedNamesInScope`.

restrictLocalPrivate :: ModuleName -> Scope -> Scope #

Remove private things from the given module from 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

publicNames :: ScopeInfo -> Set AbstractName #

everythingInScope :: ScopeInfo -> NameSpace #

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

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

concreteNamesInScope :: ScopeInfo -> Set QName #

Get all concrete names in scope. Includes bound variables.

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

data AllowAmbiguousNames #

Constructors

AmbiguousAnything | Used for instance arguments to check whether a name is in scope, but we do not care whether is is ambiguous
AmbiguousConProjs | Ambiguous constructors or projections.
AmbiguousNothing |

Instances

Eq AllowAmbiguousNames # |
Methods (==) :: AllowAmbiguousNames -> AllowAmbiguousNames -> Bool # (/=) :: AllowAmbiguousNames -> AllowAmbiguousNames -> Bool #

isNameInScope :: QName -> ScopeInfo -> Bool #

inverseScopeLookup :: Either ModuleName QName -> ScopeInfo -> [QName] #

Find the concrete names that map (uniquely) to a given abstract name. Sort by length, shortest first.

inverseScopeLookup' :: AllowAmbiguousNames -> Either ModuleName QName -> ScopeInfo -> [QName] #

recomputeInverseScopeMaps :: ScopeInfo -> ScopeInfo #

inverseScopeLookupName :: QName -> ScopeInfo -> [QName] #

Find the concrete names that map (uniquely) to a given abstract qualified name. Sort by length, shortest first.

inverseScopeLookupName' :: AllowAmbiguousNames -> QName -> ScopeInfo -> [QName] #

inverseScopeLookupModule :: ModuleName -> ScopeInfo -> [QName] #

Find the concrete names that map (uniquely) to a given abstract module name. Sort by length, shortest first.

# (Debug) printing

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

Add first string only if list is non-empty.

# Boring instances