module Dhall.Substitution where
import Data.Text (Text)
import Dhall.Normalize (subst)
import Dhall.Syntax (Expr, Var (..))
import qualified Dhall.Map
type Substitutions s a = Dhall.Map.Map Text (Expr s a)
empty :: Substitutions s a
empty :: Substitutions s a
empty = Substitutions s a
forall k v. Ord k => Map k v
Dhall.Map.empty
substitute :: Expr s a -> Substitutions s a -> Expr s a
substitute :: Expr s a -> Substitutions s a -> Expr s a
substitute Expr s a
expr = (Expr s a -> (Text, Expr s a) -> Expr s a)
-> Expr s a -> [(Text, Expr s a)] -> Expr s a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (\Expr s a
memo (Text
k, Expr s a
v) -> Var -> Expr s a -> Expr s a -> Expr s a
forall s a. Var -> Expr s a -> Expr s a -> Expr s a
subst (Text -> Int -> Var
V Text
k Int
0) Expr s a
v Expr s a
memo) Expr s a
expr ([(Text, Expr s a)] -> Expr s a)
-> (Substitutions s a -> [(Text, Expr s a)])
-> Substitutions s a
-> Expr s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Substitutions s a -> [(Text, Expr s a)]
forall k v. Ord k => Map k v -> [(k, v)]
Dhall.Map.toList