March Docs

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:

  1. Diverging (panic, todo, unreachable)
  2. Option helpers
  3. Result helpers
  4. List basics
  5. Combinators (identity, compose, flip, const)
  6. 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.
  • unwrap and unwrap_or operate on Option(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

fncomposecompose(f : b -> c, g : a -> b) : a -> c#

Function composition: compose(f, g)(x) = f(g(x)).

fnconstconst(x : a) : b -> a#

Returns a function that always returns x, ignoring its argument.

fndebugdebug(x)#

Prints a value using its Show representation, with a trailing newline.

fnfilterfilter(xs : List(a), pred : a -> Bool) : List(a)#

Returns only the elements satisfying pred.

fnflipflip(f : a -> b -> c) : b -> a -> c#

Flips the order of arguments: flip(f)(b, a) = f(a, b).

fnfold_leftfold_left(xs : List(a), acc : b, f : b -> a -> b) : b#

Left fold over a list. Argument order: collection first, init second, callback last (uncurried-collection convention).

fnheadhead(xs : {List(a) | len(_) > 0}) : a#

Returns the first element of the list. Panics if empty.

fnidentityidentity(x : a) : a#

The identity function — returns its argument unchanged.

fninspectinspect(x) do to_string(x) end#

Converts any value to its string representation.

fnis_nilis_nil(xs : List(a)) : Bool#

Returns true if the list is empty.

fnlengthlength(xs : List(a)) : Int#

Returns the number of elements in the list.

fnmapmap(xs : List(a), f : a -> b) : List(b)#

Applies f to every element of the list.

fnpanicpanic(msg : String) : a#

Terminates the program with a runtime error. Used for violated invariants — bugs, not expected failures. Propagates to the enclosing actor boundary.

fnprintlnprintln(x)#

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.

fnreversereverse(xs : List(a)) : List(a)#

Reverses a list.

fnstrstr(x) do to_string(x) end#

Short alias for to_string.

fntailtail(xs : {List(a) | len(_) > 0}) : List(a)#

Returns all but the first element. Panics if empty.

fntodotodo(msg : String) : a#

Marks code as not yet implemented. Typechecks as any type so you can sketch a program top-down. Never valid in production.

fnunreachableunreachable() : a#

Asserts that a code path is unreachable.

fnunwrapunwrap(opt : {Option(a) | is_Some(_)}) : a#

Extracts the value from Some(x), panicking if None.

fnunwrap_orunwrap_or(opt : Option(a), default : a) : a#

Returns the contained value, or default if None.