On this page
Lexical Structure
This document describes the lexical structure of Halyard source code.
Character Set
Halyard source files are UTF-8 encoded. Identifiers can contain Unicode letters.
Comments
Line Comments
-- This is a line comment
let x = 42 -- Inline comment
x
Compiled
Block Comments
{- This is a
block comment -}
{- Block comments
{- can be nested -}
like this -}
Doc Comments
Doc comments use {-| ... -} syntax. They are used by tooling (LSP hover, documentation generation) and are distinguished from regular block comments:
{-| Increments a number by one. -}
fn inc : Int -> Int
fn inc x = x + 1
{-| A multiline doc comment
explaining complex behavior. -}
fn double : Int -> Int
fn double x = x * 2
Whitespace and Indentation
Halyard uses indentation to define block structure. Indentation is significant for:
- Function bodies
- Case expression branches
- Inline module content
fn example : Int -> Int
fn example x =
let y = 1 -- Must be indented
x + y
example 1
Compiled
Identifiers
Value Identifiers
Start with lowercase letter or underscore:
name
_private
camelCase
snake_case
x1
Type Identifiers
Start with uppercase letter:
Int
String
Maybe
MyCustomType
Keywords
Reserved words that cannot be used as identifiers:
case of if then else
let in fn type mut
module import exposing as alias
True False
Note: mut is a reserved keyword for future use. It cannot be used as an identifier — Halyard is a pure functional language where all bindings are immutable.
Literals
Integer Literals
42 -- Decimal
Compiled
Float Literals
3.14
Compiled
Decimal Literals
Decimal literals use the d suffix for arbitrary-precision decimal values:
42d -- Integer decimal
3.14d -- Fractional decimal
Compiled
Character Literals
'a'
Compiled
String Literals
"Hello, World!"
Boolean Literals
True
Compiled
Unit Literal
()
Compiled
Operators
Arithmetic Operators
| Operator | Description |
|---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
// | Integer division |
% | Modulo |
^ | Power |
Comparison Operators
| Operator | Description |
|---|---|
== | Equal |
!= | Not equal |
< | Less than |
<= | Less than or equal |
> | Greater than |
>= | Greater than or equal |
Logical Operators
| Operator | Description |
|---|---|
&& | Logical AND |
|| | Logical OR |
not | Logical NOT |
Function Operators
| Operator | Description |
|---|---|
>> | Compose (left to right) |
<< | Compose (right to left) |
|> | Pipe forward |
<| | Pipe backward |
List Operators
| Operator | Description |
|---|---|
:: | Cons (prepend) |
++ | Concatenation |
Delimiters
( ) -- Grouping, tuples, unit
[ ] -- Lists, index access
{ } -- Records, blocks, block comments
, -- Separator
: -- Type annotation
-> -- Function type, case branches
= -- Definition, record fields
| -- Pattern alternatives, enum variants, lambda start
Lambda Syntax
Lambdas use pipe characters:
|x| x + 1
|x y| x + y
|x: Int| x + 1
|(x, y)| x + y
Pattern Matching Syntax
Case expressions with guards:
case value of
pattern -> result
n if n > 0 -> "positive"
_ -> "default"
Record Syntax
Records use = for field assignment:
{ name = "Alice", age = 30 }
Record update uses |:
{ person | age = 31 }
Module Syntax
-- File-level module (the whole file is the body, so it is NOT indented)
module exposing foo, bar
-- Named inline module (content must be indented)
module Math exposing add
fn add : Int -> Int -> Int
fn add x y = x + y
-- Task definition (callee file for task execution)
task expecting { x : Int } exposing { result : Int }
Task Syntax
Tasks are resolved at compile time. The run expression returns a record of exposed values:
-- Run a task, passing variables and destructuring the result
let { result } = run "file.hly" { x, y }
-- Pass all variables
let { result } = run "file.hly" { .. }
-- No variables to pass
let { answer } = run "file.hly"
Type Definition Syntax
-- Newtype (opaque, nominally distinct)
type Name = String
-- Enum type (single line)
enum Direction = North | South | East | West
-- Enum type (multi-line). A variant's fields are juxtaposed, one atom each.
enum Shape
= Circle Float
| Rectangle Float Float
| Wrap (Float, Float)
-- Enum with record variant
enum User
= Guest
| Member { name: String, id: Int }
Rectangle Float Float is two fields; Wrap (Float, Float) is one field whose
type is a pair. Parentheses group, so an applied type in a field position needs
them too: Boxed (Maybe Int) is one field, Boxed Maybe Int is two.
Enum Construction
Enum variants are curried: arguments are space-separated, and parentheses group instead of delimiting:
Shape::Circle 5.0 -- one argument
Shape::Rectangle 10.0 20.0 -- two arguments, space-separated
Shape::Wrap (10.0, 20.0) -- parentheses make ONE argument of tuple type
Qualified Enum Syntax
Enum variants use :: for qualified access, both in expressions and patterns:
let color = Color::Green
case color of
Color::Red -> "fire"
Color::Green -> "nature"
Color::Blue -> "sky"