Copyright | disco team and contributors |
---|---|
Maintainer | byorgey@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
A *context* is a mapping from names to other things (such as types or values). This module defines a generic type of contexts which is used in many different places throughout the disco codebase.
Synopsis
- data Ctx a b
- emptyCtx :: Ctx a b
- singleCtx :: QName a -> b -> Ctx a b
- fromList :: [(QName a, b)] -> Ctx a b
- ctxForModule :: ModuleName -> [(Name a, b)] -> Ctx a b
- localCtx :: [(Name a, b)] -> Ctx a b
- insert :: QName a -> b -> Ctx a b -> Ctx a b
- extend :: Member (Reader (Ctx a b)) r => QName a -> b -> Sem r c -> Sem r c
- extends :: Member (Reader (Ctx a b)) r => Ctx a b -> Sem r c -> Sem r c
- null :: Ctx a b -> Bool
- lookup :: Member (Reader (Ctx a b)) r => QName a -> Sem r (Maybe b)
- lookup' :: QName a -> Ctx a b -> Maybe b
- lookupNonLocal :: Member (Reader (Ctx a b)) r => Name a -> Sem r [(ModuleName, b)]
- lookupNonLocal' :: Name a -> Ctx a b -> [(ModuleName, b)]
- lookupAll :: Member (Reader (Ctx a b)) r => Name a -> Sem r [(QName a, b)]
- lookupAll' :: Name a -> Ctx a b -> [(QName a, b)]
- names :: Ctx a b -> [Name a]
- elems :: Ctx a b -> [b]
- assocs :: Ctx a b -> [(QName a, b)]
- keysSet :: Ctx a b -> Set (QName a)
- coerceKeys :: Ctx a1 b -> Ctx a2 b
- restrictKeys :: Ctx a b -> Set (QName a) -> Ctx a b
- joinCtx :: Ctx a b -> Ctx a b -> Ctx a b
- joinCtxs :: [Ctx a b] -> Ctx a b
- filter :: (b -> Bool) -> Ctx a b -> Ctx a b
Context type
A context maps qualified names to things. In particular a Ctx a
b
maps qualified names for a
s to values of type b
.
Instances
Functor (Ctx a) Source # | |
Foldable (Ctx a) Source # | |
Defined in Disco.Context fold :: Monoid m => Ctx a m -> m # foldMap :: Monoid m => (a0 -> m) -> Ctx a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> Ctx a a0 -> m # foldr :: (a0 -> b -> b) -> b -> Ctx a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> Ctx a a0 -> b # foldl :: (b -> a0 -> b) -> b -> Ctx a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> Ctx a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> Ctx a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> Ctx a a0 -> a0 # elem :: Eq a0 => a0 -> Ctx a a0 -> Bool # maximum :: Ord a0 => Ctx a a0 -> a0 # minimum :: Ord a0 => Ctx a a0 -> a0 # | |
Traversable (Ctx a) Source # | |
Eq b => Eq (Ctx a b) Source # | |
Show b => Show (Ctx a b) Source # | |
Semigroup (Ctx a b) Source # | |
Monoid (Ctx a b) Source # | |
Construction
singleCtx :: QName a -> b -> Ctx a b Source #
A singleton context, mapping a qualified name to a thing.
fromList :: [(QName a, b)] -> Ctx a b Source #
Create a context from a list of (qualified name, value) pairs.
ctxForModule :: ModuleName -> [(Name a, b)] -> Ctx a b Source #
Create a context for bindings from a single module.
Insertion
insert :: QName a -> b -> Ctx a b -> Ctx a b Source #
Insert a new binding into a context. The new binding shadows any old binding for the same qualified name.
extend :: Member (Reader (Ctx a b)) r => QName a -> b -> Sem r c -> Sem r c Source #
Run a computation under a context extended with a new binding. The new binding shadows any old binding for the same name.
extends :: Member (Reader (Ctx a b)) r => Ctx a b -> Sem r c -> Sem r c Source #
Run a computation in a context extended with an additional context. Bindings in the additional context shadow any bindings with the same names in the existing context.
Query
lookup :: Member (Reader (Ctx a b)) r => QName a -> Sem r (Maybe b) Source #
Look up a qualified name in an ambient context.
lookupNonLocal :: Member (Reader (Ctx a b)) r => Name a -> Sem r [(ModuleName, b)] Source #
Look up all the non-local bindings of a name in an ambient context.
lookupNonLocal' :: Name a -> Ctx a b -> [(ModuleName, b)] Source #
Look up all the non-local bindings of a name in a context.
lookupAll :: Member (Reader (Ctx a b)) r => Name a -> Sem r [(QName a, b)] Source #
Look up all the bindings of an (unqualified) name in an ambient context.
lookupAll' :: Name a -> Ctx a b -> [(QName a, b)] Source #
Look up all the bindings of an (unqualified) name in a context.
Conversion
assocs :: Ctx a b -> [(QName a, b)] Source #
Return a list of the qualified name-value associations in the context.
Traversal
coerceKeys :: Ctx a1 b -> Ctx a2 b Source #
Coerce the type of the qualified name keys in a context.
restrictKeys :: Ctx a b -> Set (QName a) -> Ctx a b Source #
Restrict a context to only the keys in the given set.
Combination
joinCtx :: Ctx a b -> Ctx a b -> Ctx a b Source #
Join two contexts (left-biased, i.e. if the same qualified name exists in both contexts, the result will use the value from the first context, and throw away the value from the second.).