Safe Haskell | None |
---|

Environment/Gamma where the lexical level + scoping is used to provide nesting behavior. Both a SGam and its entries know at which scope they are.

Insertion is efficient, lookup also, because a single Map is used.

The Map holds multiple entries, each with its own scope identifier. An SGam holds - a stack of scopes, encoding the nesting, where - each scope holds mappings for MetaLev's

Results are filtered out w.r.t. this stack, i.e. are checked to be in scope. In principle this can be done eagerly, that is, immediately after a change in scope, in particular in sgamPop. After some experimentation it did turn out that doing this lazily is overall faster, that is, when the SGam is consulted (lookup, conversion to association list, etc). Conceptually thus the invariant is that no entry is in the map which is not in scope. Guaranteeing this invariant is thus not done by the one function breaking it (sgamPop).

- data SGam k v
- emptySGam :: SGam k v
- sgamFilterMapEltAccumWithKey :: Ord k' => (k -> SGamElt v -> Bool) -> (k -> SGamElt v -> acc -> (k', SGamElt v', acc)) -> (k -> SGamElt v -> acc -> acc) -> acc -> SGam k v -> (SGam k' v', acc)
- sgamMapEltWithKey :: (Ord k, Ord k') => (k -> SGamElt v -> (k', SGamElt v')) -> SGam k v -> SGam k' v'
- sgamMapThr :: (Ord k, Ord k') => ((k, v) -> t -> ((k', v'), t)) -> t -> SGam k v -> (SGam k' v', t)
- sgamMap :: (Ord k, Ord k') => ((k, v) -> (k', v')) -> SGam k v -> SGam k' v'
- sgamPop :: Ord k => SGam k v -> (SGam k v, SGam k v)
- sgamTop :: Ord k => SGam k v -> SGam k v
- sgamPushNew :: SGam k v -> SGam k v
- sgamPushGam :: Ord k => SGam k v -> SGam k v -> SGam k v
- sgamMetaLevSingleton :: MetaLev -> k -> v -> SGam k v
- sgamSingleton :: k -> v -> SGam k v
- sgamUnionWith :: Ord k => Maybe (v -> [v] -> [v]) -> SGam k v -> SGam k v -> SGam k v
- sgamUnion :: Ord k => SGam k v -> SGam k v -> SGam k v
- sgamPartitionEltWithKey :: Ord k => (k -> SGamElt v -> Bool) -> SGam k v -> (SGam k v, SGam k v)
- sgamPartitionWithKey :: Ord k => (k -> v -> Bool) -> SGam k v -> (SGam k v, SGam k v)
- sgamUnzip :: Ord k => SGam k (v1, v2) -> (SGam k v1, SGam k v2)
- sgamAlterDupOnTop :: Ord k => (Maybe v -> Maybe v) -> k -> SGam k v -> SGam k v
- sgamLookupMetaLevDup :: Ord k => MetaLev -> k -> SGam k v -> Maybe [v]
- sgamToAssocDupL :: Ord k => SGam k v -> AssocL k [v]
- sgamFromAssocDupL :: Ord k => AssocL k [v] -> SGam k v
- sgamNoDups :: Ord k => SGam k v -> SGam k v
- type MetaLev = Int
- metaLevVal :: MetaLev

# Documentation

# Folding

sgamFilterMapEltAccumWithKey :: Ord k' => (k -> SGamElt v -> Bool) -> (k -> SGamElt v -> acc -> (k', SGamElt v', acc)) -> (k -> SGamElt v -> acc -> acc) -> acc -> SGam k v -> (SGam k' v', acc)Source

do it all: map, filter, fold

sgamMapEltWithKey :: (Ord k, Ord k') => (k -> SGamElt v -> (k', SGamElt v')) -> SGam k v -> SGam k' v'Source

sgamMapThr :: (Ord k, Ord k') => ((k, v) -> t -> ((k', v'), t)) -> t -> SGam k v -> (SGam k' v', t)Source

# Construction & Destruction

sgamPop :: Ord k => SGam k v -> (SGam k v, SGam k v)Source

split gam in top and the rest, both with the same scope

sgamPushNew :: SGam k v -> SGam k vSource

enter a new scope

sgamPushGam :: Ord k => SGam k v -> SGam k v -> SGam k vSource

enter a new scope, add g1 in that scope to g2

sgamMetaLevSingleton :: MetaLev -> k -> v -> SGam k vSource

Construct singleton gam, on a particular meta level

sgamSingleton :: k -> v -> SGam k vSource

Construct singleton gam

sgamUnionWith :: Ord k => Maybe (v -> [v] -> [v]) -> SGam k v -> SGam k v -> SGam k vSource

combine gam, g1 is added to g2 with scope of g2

sgamPartitionEltWithKey :: Ord k => (k -> SGamElt v -> Bool) -> SGam k v -> (SGam k v, SGam k v)Source

equivalent of partition

# Deletion

# Update

sgamAlterDupOnTop :: Ord k => (Maybe v -> Maybe v) -> k -> SGam k v -> SGam k vSource

Alter on top of the scope stack, including all duplicates

# Lookup

sgamLookupMetaLevDup :: Ord k => MetaLev -> k -> SGam k v -> Maybe [v]Source

lookup, return at least one found value, otherwise Nothing

# Conversion

sgamToAssocDupL :: Ord k => SGam k v -> AssocL k [v]Source

convert to association list, with all duplicates, scope is lost

sgamFromAssocDupL :: Ord k => AssocL k [v] -> SGam k vSource

convert from association list, assume default scope

sgamNoDups :: Ord k => SGam k v -> SGam k vSource

get rid of duplicate entries, by taking the first of them all

# Re-exports

Base level (of values, usually)