Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Let (Let Bindings)

Definition

Let { bindings :: [Binding], body :: Expr }

Fields

FieldTypeDescription
bindings[Binding]List of local bindings (Inherit or NamedVar)
bodyExprBody expression evaluated with bindings in scope

Nix Source ↔ AST

# Nix
let x = 1; y = 2; in x + y

# AST
{
  "tag": "Let",
  "bindings": [
    {
      "tag": "NamedVar",
      "attrPath": [{ "tag": "StaticKey", "contents": "x" }],
      "value": { "tag": "Constant", "contents": { "tag": "Int", "contents": 1 } }
    },
    {
      "tag": "NamedVar",
      "attrPath": [{ "tag": "StaticKey", "contents": "y" }],
      "value": { "tag": "Constant", "contents": { "tag": "Int", "contents": 2 } }
    }
  ],
  "body": {
    "tag": "Binary",
    "op": "+",
    "left": { "tag": "Sym", "contents": "x" },
    "right": { "tag": "Sym", "contents": "y" }
  }
}
  • Binding: Inherit and NamedVar constructors
  • With: similar but brings a set into scope

Nix Library Access

syntax.mkLet [syntax.mkNamedVar [syntax.mkStaticKey "x"] (syntax.mkInt 1)] (syntax.mkBinary "+" (syntax.mkSym "x") (syntax.mkSym "y"))