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

ParamSet (Parameter Set)

Parameter set constructor for function parameters. Part of the Params type.

Definition

ParamSet { paramSetName :: Maybe VarName, variadic :: Bool, params :: ParamSet }

Fields

FieldTypeDescription
paramSetNameMaybe VarNameName for @-pattern (e.g., args @ { x, y })
variadicBooltrue if ... is present (allows extra arguments)
paramsParamSetThe actual parameter set (map of name → optional default)

Description

ParamSet represents a function parameter set like { x, y ? 1, ... }. It contains the parameter names, their optional default values, whether it’s variadic, and an optional name for the whole set (for @-patterns).

The inner ParamSet field wraps a parameter set type that maps parameter names to optional default expressions.

type ParamSet = [(Text, Maybe Expr)]

Invariant: duplicate parameter names are semantically invalid in Nix. Each parameter name must be unique.

Nix Source ↔ AST

Fixed Parameters

# Nix
{ x, y }: x + y

# AST
{
  "tag": "Abs",
  "params": {
    "tag": "ParamSet",
    "paramSetName": null,
    "variadic": false,
    "params": [
      ["x", null],
      ["y", null]
    ]
  },
  "body": { ... }
}

With Defaults

# Nix
{ x ? 1, y ? "hello" }: x

# AST
{
  "tag": "ParamSet",
  "paramSetName": null,
  "variadic": false,
  "params": [
    ["x", { "tag": "Constant", "contents": { "tag": "Int", "contents": 1 } }],
    ["y", { "tag": "Str", "contents": { "tag": "DoubleQuoted", "contents": [{ "tag": "Plain", "contents": "hello" }] } }]
  ]
}

Variadic (...)

# Nix
{ x, y, ... }: x + y

# AST
{
  "tag": "ParamSet",
  "paramSetName": null,
  "variadic": true,
  "params": [
    ["x", null],
    ["y", null]
  ]
}

With @-Pattern

# Nix
args @ { x, y }: args.x + args.y

# AST
{
  "tag": "ParamSet",
  "paramSetName": "args",
  "variadic": false,
  "params": [
    ["x", null],
    ["y", null]
  ]
}
  • Param: single parameter constructor
  • Params: the parent sum type

Nix Library Access

syntax.mkParamSet null false [["x" null] ["y" null]]
syntax.mkParamSet null false [["x" (syntax.mkInt 1)]]
syntax.mkParamSet null true [["x" null] ["y" null]]
syntax.mkParamSet "args" false [["x" null] ["y" null]]