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

If (Conditional)

Definition

If { cond :: Expr, thenExpr :: Expr, elseExpr :: Expr }

Fields

FieldTypeDescription
condExprCondition expression (must evaluate to boolean)
thenExprExprExpression when condition is true
elseExprExprExpression when condition is false

Nix Source ↔ AST

# Nix
if cond then 1 else 2

# AST
{
  "tag": "If",
  "cond": { "tag": "Sym", "contents": "cond" },
  "thenExpr": { "tag": "Constant", "contents": { "tag": "Int", "contents": 1 } },
  "elseExpr": { "tag": "Constant", "contents": { "tag": "Int", "contents": 2 } }
}

Nix Library Access

syntax.mkIf cond thenExpr elseExpr