Skip to main content

Introduction

Elara’s standard library provides essential modules and functions for common programming tasks. The standard library is automatically available when you import the Prelude module, which re-exports commonly used functionality.

Core Modules

The standard library is organized into focused modules:

Prelude

Core utilities and operators imported by default

List

Functions for working with linked lists

String

String manipulation and concatenation

Option

Optional values for safe null handling

Result

Error handling with Result types

Elara.Prim

Primitive types and operations

Importing Modules

To use standard library modules in your code, import them at the top of your file:
import Prelude        -- Core utilities (pipe, composition, etc.)
import List          -- List operations
import String        -- String functions
import Option        -- Option type
import Result        -- Result type
import Elara.Prim    -- Primitive types and operations
The Prelude module is typically imported in most Elara programs as it provides essential operators and utilities.

Design Philosophy

Functional First

Elara’s standard library is designed with functional programming principles:
  • Immutability: All data structures are immutable by default
  • Pure Functions: Functions have no side effects (except IO operations)
  • Type Safety: Strong static typing catches errors at compile time
  • Composability: Functions are designed to work together seamlessly

Minimal and Focused

Each module provides a focused set of functions:
Operations for working with linked lists including append, zip, reverse, flatten, and more.
String concatenation, conversion between strings and character lists, and joining.
Safe handling of nullable values with Some and None constructors.
Error handling with Ok and Err constructors, including map and bind operations.

Common Patterns

Pipeline Operator

The pipeline operator |> from Prelude enables readable data transformations:
import Prelude
import List

let result = [1, 2, 3, 4, 5]
    |> List.map (\x -> x * 2)
    |> List.filter (\x -> x > 5)
    |> List.reverse

Pattern Matching

All standard library types support pattern matching:
import Option

def describe : Option Int -> String
let describe opt =
    match opt with
        Some val -> "Got value: " ++ toString val
        None -> "Got nothing"

Function Composition

Compose functions using the >> operator:
import Prelude

let addOne = (\x -> x + 1)
let double = (\x -> x * 2)
let addOneThenDouble = addOne >> double

-- addOneThenDouble 5 == 12

Primitive Types

Elara provides these primitive types in Elara.Prim:
TypeDescription
IntInteger numbers
FloatFloating-point numbers
CharSingle characters
StringText strings
BoolBoolean values (True or False)
UnitThe unit type ()
IO aIO operations that produce values of type a

Next Steps

Prelude

Learn about core operators and utilities

List Operations

Master list manipulation functions

Error Handling

Handle errors with Result types

Examples

See the standard library in action

Build docs developers (and LLMs) love