Write a handl script
This guide shows how to write, save, and run a self-contained handl script.
File layout
A handl script is a text file with the .hnl extension. It contains an expression that the runtime evaluates and prints.
Example greet.hnl:
handl
name: type.string = "handl";
greeting: type.string = str.concat(["Hello, ", name, "!"]);
greetingRunning the script
Use the CLI:
sh
hnl run greet.hnlUsing modules
Import capabilities from modules as needed. Most modules are available by default in the runtime; you call them with module.function syntax.
handl
raw: type.string = " padded ";
clean: type.string = str.trim(raw);
upper: type.string = str.upper(clean);
upperThis evaluates to "PADDED".
Working with JSON data
handl is JSON-native. You can read and transform JSON data directly:
handl
Package: type.object = {
name: type.string,
version: type.string
};
data: Package = {
name: "handl",
version: "0.1.0"
};
name_ok: type.bool = data.name is type.string;
data.nameResult:
"handl"Refinements
A function returning type.bool can be used as a refinement type after ::
handl
NonEmpty = (s: type.string) -> str.length(s) > 0;
greeting: NonEmpty = "Hello, handl!";
greetingResult:
"Hello, handl!"Tips
- Keep one expression per script or clearly chain let bindings.
- Refer to the reference for
array,str, andmathhelpers. - Use
math.sumandmath.avgfor numeric summaries,array.compactto remove nulls.