Portability | portable |
---|---|
Stability | alpha |
Maintainer | jwlato@gmail.com |
Safe Haskell | None |
This module manages name spaces.
- A name space map associates identifiers with their definition.
- Each name space map is organized in a hierarchical way using the notion of scopes. A name space map, at any moment, always has a global scope and may have several local scopes. Definitions in inner scopes hide definitions of the same identifier in outer scopes.
- data NameSpaceMap k v
- nameSpaceMap :: Ord k => NameSpaceMap k v
- nsMapToList :: Ord k => NameSpaceMap k a -> [(k, a)]
- globalNames :: Ord k => NameSpaceMap k v -> Map k v
- localNames :: Ord k => NameSpaceMap k v -> [[(k, v)]]
- hasLocalNames :: NameSpaceMap k v -> Bool
- defGlobal :: Ord k => NameSpaceMap k a -> k -> a -> (NameSpaceMap k a, Maybe a)
- enterNewScope :: Ord k => NameSpaceMap k a -> NameSpaceMap k a
- leaveScope :: Ord k => NameSpaceMap k a -> (NameSpaceMap k a, [(k, a)])
- defLocal :: Ord k => NameSpaceMap k a -> k -> a -> (NameSpaceMap k a, Maybe a)
- lookupName :: Ord k => NameSpaceMap k a -> k -> Maybe a
- lookupGlobal :: Ord k => NameSpaceMap k a -> k -> Maybe a
- lookupInnermostScope :: Ord k => NameSpaceMap k a -> k -> Maybe a
- mergeNameSpace :: Ord k => NameSpaceMap k a -> NameSpaceMap k a -> NameSpaceMap k a
name space maps
data NameSpaceMap k v Source
NameSpaceMap a
is a Map from identifiers to a
, which manages
global and local name spaces.
nameSpaceMap :: Ord k => NameSpaceMap k vSource
create a name space
nsMapToList :: Ord k => NameSpaceMap k a -> [(k, a)]Source
flatten a namespace into a assoc list
nameSpaceToList ns = (localDefInnermost ns ++ .. ++ localDefsOutermost ns) ++ globalDefs ns
globalNames :: Ord k => NameSpaceMap k v -> Map k vSource
localNames :: Ord k => NameSpaceMap k v -> [[(k, v)]]Source
hasLocalNames :: NameSpaceMap k v -> BoolSource
scope modification
defGlobal :: Ord k => NameSpaceMap k a -> k -> a -> (NameSpaceMap k a, Maybe a)Source
Add global definition
(ns',oldDef) = defGlobal ns ident def
adds a global definition ident := def
to the namespace.
It returns the modified namespace ns'
. If the identifier is
already declared in the global namespace, the definition is overwritten
and the old definition oldDef
is returned.
enterNewScope :: Ord k => NameSpaceMap k a -> NameSpaceMap k aSource
Enter new local scope
ns' = enterNewScope ns
creates and enters a new local scope.
leaveScope :: Ord k => NameSpaceMap k a -> (NameSpaceMap k a, [(k, a)])Source
Leave innermost local scope
(ns',defs) = leaveScope ns
pops leaves the innermost local scope.
and returns its definitions
defLocal :: Ord k => NameSpaceMap k a -> k -> a -> (NameSpaceMap k a, Maybe a)Source
Add local definition
(ns',oldDef) = defLocal ns ident def
adds the local definition
ident := def
to the innermost local scope, if there is a local scope,
and to the global scope otherwise.
It returns the modified name space ns'
and the old binding of
the identifier oldDef
, which is overwritten.
lookupName :: Ord k => NameSpaceMap k a -> k -> Maybe aSource
Search for a definition
def = find ns ident
returns the definition in some scope (inner to outer),
if there is one.
lookupGlobal :: Ord k => NameSpaceMap k a -> k -> Maybe aSource
lookupInnermostScope :: Ord k => NameSpaceMap k a -> k -> Maybe aSource
mergeNameSpace :: Ord k => NameSpaceMap k a -> NameSpaceMap k a -> NameSpaceMap k aSource
Merge two namespaces. If they disagree on the types of any variables, all bets are off.