dhall-1.9.0: A configuration language guaranteed to terminate

Safe HaskellNone
LanguageHaskell98

Dhall.Context

Contents

Description

This is a utility module that consolidates all Context-related operations

Synopsis

Context

data Context a Source #

A (Context a) associates Text labels with values of type a. Each Text label can correspond to multiple values of type a

The Context is used for type-checking when (a = Expr X)

The difference between a Context and a Map is that a Context lets you have multiple ordered occurrences of the same key and you can query for the nth occurrence of a given key.

Instances

Functor Context Source # 

Methods

fmap :: (a -> b) -> Context a -> Context b #

(<$) :: a -> Context b -> Context a #

empty :: Context a Source #

An empty context with no key-value pairs

insert :: Text -> a -> Context a -> Context a Source #

Add a key-value pair to the Context

lookup :: Text -> Integer -> Context a -> Maybe a Source #

Look up a key by name and index

lookup _ _         empty  = Nothing
lookup k 0 (insert k v c) = Just v
lookup k n (insert k v c) = lookup k (n - 1) c
lookup k n (insert j v c) = lookup k  n      c  -- k /= j

toList :: Context a -> [(Text, a)] Source #

Return all key-value associations as a list

toList           empty  = []
toList (insert k v ctx) = (k, v) : toList ctx