On this page
Basics
This chapter covers the fundamental concepts of Halyard.
Values and Types
Halyard is a statically typed language with type inference. Here are the basic types:
-- Numbers
let intVal = 42 -- Int
let floatVal = 3.14 -- Float
let price = 19.99d -- Decimal (exact precision)
-- Strings and Characters
let greeting = "Hello" -- String
let letter = 'a' -- Char
-- Booleans
let yes = True -- Bool
let no = False -- Bool
-- Unit (like void)
let unit = ()
greeting
Compiled
Variables
Variables are declared with let and are immutable:
let x = 42
let name = "Alice"
let pi = 3.14159
name ++ " loves pi"
Compiled
To "update" a value, use variable shadowing (re-declaring with the same name):
let x = 1
let x = x + 1
x
Compiled
Comments
-- This is a line comment
{- This is a
block comment -}
let x = 42 -- inline comment
x
Compiled
Halyard also supports doc comments for tooling (LSP hover, documentation generation):
{-| Increments a number by one. -}
fn inc : Int -> Int
fn inc x =
x + 1
inc 1
Compiled
Indentation
Halyard uses significant indentation to define code blocks, similar to Python or Haskell. Nested code must be indented further than its parent:
fn example : Int -> Int
fn example x =
let y = 1 -- Block must be indented
x + y
example 5
Compiled
Consistent indentation within a block is required:
let condition = True
if condition then
"result1"
else
"result2" -- Must align with 'result1'
Compiled
For inline modules, content must be indented:
module CustomMath exposing add
fn add : Int -> Int -> Int
fn add x y =
x + y
CustomMath.add 3 4
Compiled
Both spaces and tabs are accepted, but be consistent within your codebase. The recommended style is 4 spaces per indentation level.
For a detailed explanation of how indentation affects parsing — especially the difference between multilines parsed as arguments vs separate expressions — see Indentation and Scope.
Functions
Functions are first-class values in Halyard:
fn add : Int -> Int -> Int
fn add x y =
x + y
add 2 3 -- Returns 5
Compiled
Operators
Halyard supports standard operators:
-- Arithmetic
let sum = 1 + 2
let diff = 5 - 3
let prod = 4 * 2
let quot = 10.0 / 3.0
let intDiv = 10 // 3
let power = 2 ^ 8
-- Comparison
let eq = 1 == 1
let neq = 1 != 2
let lt = 1 < 2
let gt = 2 > 1
-- Logical
let andOp = True && False
let orOp = True || False
let notOp = not True -- Not: False
-- String
let concat = "Hello" ++ " World"
-- List
let consed = 1 :: [2, 3]
let joined = [1, 2] ++ [3, 4]
concat
Compiled
Next Steps
Continue to learn about indentation and scope for understanding how multiline code is parsed, or jump to functions for function definitions and usage.