The Prelude module provides essential operators and utilities that form the foundation of Elara programming. It includes function composition, pipeline operators, and IO sequencing operations.
Left-associative pipeline operator (fixity 0). Applies a value to a function, enabling readable left-to-right data flow.
Signature:
def (|>) : a -> (a -> b) -> b
Description:The pipeline operator takes a value and a function, then applies the function to the value. This allows you to write data transformations in a natural left-to-right order.Example:
Right-associative function composition. Composes two functions into a new function.
Signature:
def (>>) : (a -> b) -> (b -> c) -> (a -> c)
Description:Composes two functions, creating a new function that applies the first function and then the second. The output type of the first function must match the input type of the second.Example:
import Preludeimport Elara.Primlet addOne = \x -> x + 1let double = \x -> x * 2-- Compose: first add one, then doublelet addOneThenDouble = addOne >> doublelet result = addOneThenDouble 5 -- 12
Right-associative IO sequencing operator (fixity 1). Executes two IO actions in sequence, discarding the first result.
Signature:
def (*>) : IO a -> IO b -> IO b
Description:Sequences two IO actions, running the first action and discarding its result, then running the second action and returning its result. This is useful for chaining IO operations where you don’t need intermediate results.Example:
type Ordering = LT | EQ | GTdef compare : a -> a -> Orderingdef (<) : a -> a -> Booldef (>) : a -> a -> Booldef (<=) : a -> a -> Booldef (>=) : a -> a -> Bool
Example:
import Elara.Primlet x = 5let y = 10let isLess = x < y -- Truelet ordering = compare x y -- LT
Prints a debug message and returns the value unchanged. Useful for debugging.
Example:
import Elara.Primdef safeHead : List a -> alet safeHead list = match list with Cons x _ -> x Nil -> error "Cannot get head of empty list"let debugValue = debugWithMsg "x = " 42 -- Prints "x = 42", returns 42
The error function causes the program to crash. For recoverable errors, use the Result type from the Result module instead.