Skip to content
Halyard
Project
Source code on Codeberg (opens in new tab)

Search

Menu

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

halyard
-- This is a line comment
let x = 42  -- Inline comment

x

Block Comments

halyard
{- 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:

halyard
{-| 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
halyard
fn example : Int -> Int
fn example x =
    let y = 1  -- Must be indented
    x + y

example 1

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

halyard
42  -- Decimal

Float Literals

halyard
3.14

Decimal Literals

Decimal literals use the d suffix for arbitrary-precision decimal values:

halyard
42d  -- Integer decimal

3.14d  -- Fractional decimal

Character Literals

halyard
'a'

String Literals

halyard
"Hello, World!"

Boolean Literals

halyard
True

Unit Literal

halyard
()

Operators

Arithmetic Operators

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
//Integer division
%Modulo
^Power

Comparison Operators

OperatorDescription
==Equal
!=Not equal
<Less than
<=Less than or equal
>Greater than
>=Greater than or equal

Logical Operators

OperatorDescription
&&Logical AND
||Logical OR
notLogical NOT

Function Operators

OperatorDescription
>>Compose (left to right)
<<Compose (right to left)
|>Pipe forward
<|Pipe backward

List Operators

OperatorDescription
::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:

halyard
|x| x + 1
|x y| x + y
|x: Int| x + 1
|(x, y)| x + y

Pattern Matching Syntax

Case expressions with guards:

halyard
case value of
    pattern -> result
    n if n > 0 -> "positive"
    _ -> "default"

Record Syntax

Records use = for field assignment:

halyard
{ name = "Alice", age = 30 }

Record update uses |:

halyard
{ person | age = 31 }

Module Syntax

halyard
-- 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:

halyard
-- 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

halyard
-- 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:

halyard
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:

halyard
let color = Color::Green

case color of
    Color::Red   -> "fire"
    Color::Green -> "nature"
    Color::Blue  -> "sky"