Safe Haskell | Safe |
---|---|

Language | Haskell98 |

Generic environment that handles both named and anonymous de-bruijn binders.

- data Bind n
- data Bound n
- data Env n a = Env {
- envMap :: !(Map n a)
- envStack :: ![a]
- envStackLength :: !Int

- fromList :: Ord n => [(Bind n, a)] -> Env n a
- fromNameList :: Ord n => [(n, a)] -> Env n a
- fromNameMap :: Map n a -> Env n a
- empty :: Env n a
- singleton :: Ord n => Bind n -> a -> Env n a
- extend :: Ord n => Bind n -> a -> Env n a -> Env n a
- extends :: Ord n => [(Bind n, a)] -> Env n a -> Env n a
- union :: Ord n => Env n a -> Env n a -> Env n a
- unions :: Ord n => [Env n a] -> Env n a
- member :: Ord n => Bound n -> Env n a -> Bool
- lookup :: Ord n => Bound n -> Env n a -> Maybe a
- lookupName :: Ord n => n -> Env n a -> Maybe a
- lookupIx :: Ord n => Int -> Env n a -> Maybe a
- depth :: Env n a -> Int

# Types

A binding occurrence of a variable.

A bound occurrence of a variable.

Generic environment that maps a variable to a thing of type `a`

.

# Conversion

fromNameMap :: Map n a -> Env n a Source #

Convert a map of things to an environment.

# Constructors

extend :: Ord n => Bind n -> a -> Env n a -> Env n a Source #

Extend an environment with a new binding. Replaces bindings with the same name already in the environment.

extends :: Ord n => [(Bind n, a)] -> Env n a -> Env n a Source #

Extend an environment with a list of new bindings. Replaces bindings with the same name already in the environment.

union :: Ord n => Env n a -> Env n a -> Env n a Source #

Combine two environments. If both environments have a binding with the same name, then the one in the second environment takes preference.

unions :: Ord n => [Env n a] -> Env n a Source #

Combine multiple environments, with the latter ones taking preference.

# Lookup

member :: Ord n => Bound n -> Env n a -> Bool Source #

Check whether a bound variable is present in an environment.

lookup :: Ord n => Bound n -> Env n a -> Maybe a Source #

Lookup a bound variable from an environment.

lookupName :: Ord n => n -> Env n a -> Maybe a Source #

Lookup a value from the environment based on its name.