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

Assert

Definition

Assert { cond :: Expr, body :: Expr }

Fields

FieldTypeDescription
condExprCondition that must evaluate to true
bodyExprExpression to evaluate if assertion passes

Nix Source ↔ AST

# Nix
assert x > 0; x + 1

# AST
{
  "tag": "Assert",
  "cond": {
    "tag": "Binary",
    "op": ">",
    "left": { "tag": "Sym", "contents": "x" },
    "right": { "tag": "Constant", "contents": { "tag": "Int", "contents": 0 } }
  },
  "body": {
    "tag": "Binary",
    "op": "+",
    "left": { "tag": "Sym", "contents": "x" },
    "right": { "tag": "Constant", "contents": { "tag": "Int", "contents": 1 } }
  }
}

Nix Library Access

syntax.mkAssert cond body