Copyright | Brent Yorgey |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Generic contexts (mappings from variables to other things, such as types, values, or capability sets) used throughout the codebase.
Synopsis
- type Var = Text
- newtype Ctx t = Ctx {}
- empty :: Ctx t
- singleton :: Var -> t -> Ctx t
- lookup :: Var -> Ctx t -> Maybe t
- delete :: Var -> Ctx t -> Ctx t
- assocs :: Ctx t -> [(Var, t)]
- addBinding :: Var -> t -> Ctx t -> Ctx t
- union :: Ctx t -> Ctx t -> Ctx t
- withBinding :: MonadReader (Ctx t) m => Var -> t -> m a -> m a
- withBindings :: MonadReader (Ctx t) m => Ctx t -> m a -> m a
Documentation
A context is a mapping from variable names to things.
Instances
Foldable Ctx Source # | |
Defined in Swarm.Language.Context fold :: Monoid m => Ctx m -> m # foldMap :: Monoid m => (a -> m) -> Ctx a -> m # foldMap' :: Monoid m => (a -> m) -> Ctx a -> m # foldr :: (a -> b -> b) -> b -> Ctx a -> b # foldr' :: (a -> b -> b) -> b -> Ctx a -> b # foldl :: (b -> a -> b) -> b -> Ctx a -> b # foldl' :: (b -> a -> b) -> b -> Ctx a -> b # foldr1 :: (a -> a -> a) -> Ctx a -> a # foldl1 :: (a -> a -> a) -> Ctx a -> a # elem :: Eq a => a -> Ctx a -> Bool # maximum :: Ord a => Ctx a -> a # | |
Traversable Ctx Source # | |
Functor Ctx Source # | |
HasBindings UCtx Source # | |
Defined in Swarm.Language.Typecheck | |
FromJSON t => FromJSON (Ctx t) Source # | |
ToJSON t => ToJSON (Ctx t) Source # | |
Defined in Swarm.Language.Context | |
Data t => Data (Ctx t) Source # | |
Defined in Swarm.Language.Context gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ctx t -> c (Ctx t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ctx t) # dataTypeOf :: Ctx t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Ctx t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Ctx t)) # gmapT :: (forall b. Data b => b -> b) -> Ctx t -> Ctx t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ctx t -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ctx t -> r # gmapQ :: (forall d. Data d => d -> u) -> Ctx t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Ctx t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ctx t -> m (Ctx t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ctx t -> m (Ctx t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ctx t -> m (Ctx t) # | |
Monoid (Ctx t) Source # | |
Semigroup (Ctx t) Source # | The semigroup operation for contexts is right-biased union. |
Generic (Ctx t) Source # | |
Show t => Show (Ctx t) Source # | |
Eq t => Eq (Ctx t) Source # | |
AsEmpty (Ctx t) Source # | |
Defined in Swarm.Language.Context | |
PrettyPrec t => PrettyPrec (Ctx t) Source # | |
Defined in Swarm.Language.Pretty | |
type Rep (Ctx t) Source # | |
Defined in Swarm.Language.Context |
addBinding :: Var -> t -> Ctx t -> Ctx t Source #
Add a key-value binding to a context (overwriting the old one if the key is already present).
withBinding :: MonadReader (Ctx t) m => Var -> t -> m a -> m a Source #
Locally extend the context with an additional binding.
withBindings :: MonadReader (Ctx t) m => Ctx t -> m a -> m a Source #
Locally extend the context with an additional context of bindings.