Prelude
March Standard Library Prelude
Everything in this module is auto-imported into every March program. These are the most commonly needed functions and types.
Sections:
- Diverging (panic, todo, unreachable)
- Option helpers
- Result helpers
- List basics
- Combinators (identity, compose, flip, const)
- String helpers
Naming overlap with module-qualified APIs is intentional:
head,tail,is_nil,length,reverse,fold_left,
`filter`, `map` are all List-typed in the prelude (their
signatures fix `xs : List(a)`), so `length(xs)` always means
`List.length(xs)`. Strings have no `length` — use
`String.byte_size` / `String.codepoint_count` instead. The
absence of a generic `length` prevents silent type confusion.unwrapandunwrap_oroperate onOption(a). For Result
call `Result.unwrap` directly.New code should prefer module-qualified calls for readability; prelude names exist for short scripts and for the few cases (head, tail, length, reverse) where the unqualified name reads better.
Functions
Function composition: compose(f, g)(x) = f(g(x)).
Returns a function that always returns x, ignoring its argument.
Prints a value using its Show representation, with a trailing newline.
Returns only the elements satisfying pred.
Flips the order of arguments: flip(f)(b, a) = f(a, b).
Left fold over a list. Argument order: collection first, init second, callback last (uncurried-collection convention).
Returns the first element of the list. Panics if empty.
The identity function — returns its argument unchanged.
Converts any value to its string representation.
Returns true if the list is empty.
Returns the number of elements in the list.
Applies f to every element of the list.
Terminates the program with a runtime error. Used for violated invariants — bugs, not expected failures. Propagates to the enclosing actor boundary.
Prints any Show value followed by a newline. Works for Int, Float, String, Bool, List, Option, Result, and any type with an explicit impl Show.
Reverses a list.
Short alias for to_string.
Returns all but the first element. Panics if empty.
Marks code as not yet implemented. Typechecks as any type so you can sketch a program top-down. Never valid in production.
Asserts that a code path is unreachable.
Extracts the value from Some(x), panicking if None.
Returns the contained value, or default if None.